在 WildFly 中找不到 Nashorn 类 [英] Nashorn class not found in WildFly
问题描述
我需要在 WildFly 中运行的 Web 应用程序中从 nashorn 访问内部类.
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");
System.out.println(cls);
}
}
但是当我在 WildFly 中运行时,以下 servlet 抛出 ClassNotFoundException:
But the following servlet is throwing a ClassNotFoundException when I run inside WildFly:
@WebServlet("/nashorn")
public class NashornServlet extends HttpServlet {
@Override
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);
}
}
}
这是服务器日志:https://gist.github.com/csokol/b81633bdbfa09bb55e2b
推荐答案
看起来 nashorn 使用的所有包/类都存在疏忽.
Looks like there was an oversight in what all packages / classes nashorn uses.
您需要打开 WILDFLY_HOME/modules/system/layers/base/sun/jdk/main/module.xml文件并添加
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.
作为参考,这是这个文件在 8.x 中的样子 分支
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
这篇关于在 WildFly 中找不到 Nashorn 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!