We'd like to create WORD files from a script.
For this, we consider using the external library https://www.javadocx.com/documentation. This is basically a .jar file.
console.log("New Archi Script");
var mydocx = Java.type("com.javadocx.CreateDocx");
var thedoc = new mydocx();
//thedoc.addText("And now the same link with some additional formatting:");
However, there is a class not found exception. Is there a way to modify the classpath and use external .jar files to reference from within scripts?
I'm not sure changing the classpath is possible as I think it's the classpath of jArchi itself, unless someone has done this before. Maybe you could spawn another Java process and command with the right classpath?
Where would you do that? Are you refering to the $EXEC command in Nashorn? I don't think this would work, because I need the connection between the objects in the Archi model and the WORD commands.
Or do you mean we could start Archi directly with another classpath?
I think it's likely that because of the way that Eclipse-based plugins have their own classpath that the classpath can only be set in jArchi itself when jArchi is compiled. Unless anyone knows different I would say that this is not possible afterwards.
thanks for your help and pointers - we've now found a (somewhat ugly) workaround to solve our issue.
We've recompiled the Script plugin with the additional classpath from within the Eclipse RCP development environment.
In addition, the lib/javadocx.jar must be added to com.archimatetool.script_0.7.1.202001311431.jar.
With these two changes it works and the full functionality of javadocx is available, great!
That is the correct (and probably only) way to do it for any additional dependency. Eclipse plug-ins are OSGi bundles and the classpath and all dependencies have to be declared in the bundle itself. That's just the way it is.
See https://forum.archimatetool.com/index.php?topic=958.0 for how to add a jar to the classpath in Nashorn and in GraalVM.
I also added the info to the wiki - https://github.com/archimatetool/archi-scripting-plugin/wiki/Runtime-Options
Very useful to know how to achive this in GraalVM!
Recently, I'm doing a lot of scripting and have switched to Graal due to its support for classes.
I'm working on generic "virtual views" that are fully driven by parametrized JScripts.