Adding the JavaScript engine "nashorn" to Eclipse Virgo

This post explains how to expose the JavaScript engine Nashorn within the OSGi server Eclipse Virgo.

Add the Java library nashorn.jar available inside your Java installation at jre/ext to your Virgo installation's endorsed folder: VIRGO_HOME/lib/endorsed.

Start Virgo and connect to the Equinox console and check that the jdk.nashorn.api.scripting.NashornScriptEngineFactory can be loaded with the clload command:

osgi> clload jdk.nashorn.api.scripting.NashornScriptEngineFactory

Successfully loaded [jdk.nashorn.api.scripting.NashornScriptEngineFactory] from:
  0 org.eclipse.osgi
  131   org.eclipse.virgo.management.console
        [provided by 0 org.eclipse.osgi

This won't be enough to allow an OSGi bundle to load the ScriptEngine:

Resolver report:
    An Import-Package could not be resolved. <...>
         constraint: <Import-Package: jdk.nashorn.api.scripting; version="0.0.0">

In VIRGO_HOME/configuration/java7-server.profile add the package to org.osgi.framework.system.packages and to org.osgi.framework.bootdelegation:

org.osgi.framework.system.packages = \
 ...,\
 jdk.nashorn.api.scripting
org.osgi.framework.bootdelegation = \
 ...,\
 jdk.*

Restart your Virgo and double check the result with clhas.

Show Comments