Author: Peter_Jodeleit
Publication Date: 6/30/2010 15:26
With JSR-223 you can use the embedded JavaScript engine of Java 6 (beware, this will not work on clients running on Java 5).
Just start your script code with #!javascript in the first line.
Btw. the line "#!beanshell" could be omitted - BeanShell is (for historical reasons) the default script engine.
Tags: beanshell, firstspirit, Javascript, jsr-223
Kommentare
6 Kommentare
What about integrating, for example, groovy as script engine? It also implements the JSR-223 interface. I've tried to publish the groovy-all (1.7.4) as global library module on the server, but it didn't work. Do you see any chance to use anything different to JS & BSH?
It's certainly possible, I know that Peter created a groovy module as a proof of concept about 2,5 years ago. In addition to the groovy-all library, he used the groovy-engine.jar from https://scripting.dev.java.net/servlets/ProjectDocumentList (located in build/groovy). You need to add the GroovyScriptEngineFactory as a public component. I'm not sure if it that jar is still necessary, because groovy ships with a similar class now.
Please keep in mind that adding a new scripting language isn't officially supported. It should work, but it's completely untested.
Hey Christoph,
thanks for the feedback. I'll give it a try and report back with any results. And yes, I'm aware of the support-issue :smileywink: This more for the one-time scripts, not for customer-deployment.
Ok, I've tried the following module.xml, but without success...
Any clues?
Here's how Peter did it 2,5 years ago. Key difference is the use of a library component for the jars.
<module>
<name>Groovy</name>
<version>4.0.122</version>
<description>Groovy Scripting Engine</description>
<vendor>e-Spirit AG</vendor>
<components>
<public>
<name>groovy</name>
<class>com.sun.script.groovy.GroovyScriptEngineFactory</class>
</public>
<library>
<name>groovy lib</name>
<resources>
<resource>lib/groovy-engine.jar</resource>
<resource>lib/groovy-all-1.5.6.jar</resource>
</resources>
</library>
</components>
</module>
Ok, that really helped :smileywink:
Just to point out the problem for anybody else:
I've used the public module type and the groovy-all-xxx.jar as resource. This won't work, so the good way to get things up and running is to use a library type to provide the jar to the classloader.
Attention: The <name/> of the public part is the name you must write after your script type definition (she-bang line).
e.x.:
<name>groovyIntegration</name> => //!groovyIntegration or #!groovyIntegration
<name>groovy</name> => //!groovy or #!groovy
Just keep it in mind :smileywink:
Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.