JSR-223 in FirstSpirit

Peter_Jodeleit
Crownpeak employee
Crownpeak employee
0 6 1,762

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.

6 Comments
mariomueller
I'm new here

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?

feddersen
Community Manager
Community Manager

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.

mariomueller
I'm new here

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 Smiley Wink This more for the one-time scripts, not for customer-deployment.

mariomueller
I'm new here

Ok, I've tried the following module.xml, but without success...

<!DOCTYPE module SYSTEM "http://www.FirstSpirit.de/module.dtd">
<module>
   <name>Groovy Integration Module</name>
   <version>4.2.206-1.7.4</version>
   <description>Groovy Integration</description>
   <vendor>...</vendor>
   <components>
       <public>
           <name>grint</name>
           <description>Bereitstellung der Groovy Bibliothek</description>
        <version>1</version>
        <class>org.codehaus.groovy.jsr223.GroovyScriptEngineFactory</class>
        <hidden>false</hidden>
        <resources>
            <resource>lib/groovy-all-1.7.4.jar</resource>
        </resources>
    </public>
   </components>
</module>

Any clues?

feddersen
Community Manager
Community Manager

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>

mariomueller
I'm new here

Ok, that really helped Smiley Wink

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 Smiley Wink

Version history
Last update:
‎06-30-2010 08:26 AM
Updated by: