Nashorn class not found in WildFly

Go To


I need to access an internal class from nashorn inside a web application running in WildFly.

The following code is working fine in my machine:

public class NashornTest {
    public static void main(String[] args) throws ClassNotFoundException {
        Class<?> cls = Class.forName("jdk.nashorn.internal.objects.ScriptFunctionImpl");

But the following servlet is throwing a ClassNotFoundException when I run inside WildFly:

public class NashornServlet extends HttpServlet {
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Class<?> cls = null;
        try {
            cls = Class.forName("jdk.nashorn.internal.objects.ScriptFunctionImpl");
        } catch (ClassNotFoundException e) {
            throw new ServletException(e);

Here's the server log:

2014-06-29 17:19
by Chico Sokol


Looks like there was an oversight in what all packages / classes nashorn uses.

You will need to open WILDFLY_HOME/modules/system/layers/base/sun/jdk/main/module.xml file and add

<path name="jdk/nashorn/api/scripting"/>
<path name="jdk/nashorn/api/scripting/resources"/>
<path name="jdk/nashorn/internal/codegen"/>
<path name="jdk/nashorn/internal/codegen/types"/>
<path name="jdk/nashorn/internal/ir"/>
<path name="jdk/nashorn/internal/ir/annotations"/>
<path name="jdk/nashorn/internal/ir/debug"/>
<path name="jdk/nashorn/internal/ir/visitor"/>
<path name="jdk/nashorn/internal/lookup"/>
<path name="jdk/nashorn/internal/objects"/>
<path name="jdk/nashorn/internal/objects/annotations"/>
<path name="jdk/nashorn/internal/parser"/>
<path name="jdk/nashorn/internal/runtime"/>
<path name="jdk/nashorn/internal/runtime/arrays"/>
<path name="jdk/nashorn/internal/runtime/linker"/>
<path name="jdk/nashorn/internal/runtime/options"/>
<path name="jdk/nashorn/internal/runtime/regexp"/>
<path name="jdk/nashorn/internal/runtime/regexp/joni"/>
<path name="jdk/nashorn/internal/runtime/resources"/>
<path name="jdk/nashorn/internal/runtime/resources/fx"/>
<path name="jdk/nashorn/internal/runtime/scripts"/>
<path name="jdk/nashorn/internal/tools"/>
<path name="jdk/nashorn/internal/tools/resources"/>
<path name="jdk/internal/dynalink"/>
<path name="jdk/internal/dynalink/beans"/>
<path name="jdk/internal/dynalink/linker"/>
<path name="jdk/internal/dynalink/support"/>

and any other path/package that might be missing.

for reference, this is how this file looks in 8.x branch

I also created Pull requests to fix this in WildFly master and 8.x branch

2014-07-01 10:45
by ctomc
thanks! I hope wildfly team accept your pull reques - Chico Sokol 2014-07-06 21:12


When running under security manager with the Java platform default security policy (or compatible extension of it), any class in jdk.nashorn.internal.* is "privileged" and hence not accessible to a caller unless specifically allowed to access (see package.access property $JDK/jre/lib/security/ file). Also, as you can see from the name, this class is internal. If you can elaborate of the use-case (i.e., why you need to access ScriptFunctionImpl), we may be able to suggest a different approach.

2014-06-30 03:10
by A. Sundararajan