我们在一些 ANT 构建文件中使用嵌入的 JavaScript 代码,并在 Java 8+ 中内置了 Nashorn 功能。在 Java 15 中,Nashorn 功能已被删除,因此我们使用独立的nashorn.jar文件对其进行了测试。我们刚刚添加:
<classpath> <pathelement location="<path>/nashorn.jar"/> </classpath>
事情进展顺利。对于 Java 16,这在构建 16+27 中运行良好。
当我运行一个简单的测试 ANT 脚本时,从 java 16+29(及更高版本)开始:
<project name="Test" default="build" basedir=".">
<target name="build">
<echo message="Begin"/>
<script language="javascript">
<classpath> <pathelement location="C:/nashorn/nashorn-0.1.0.2013070801.jar"/> </classpath>
print('Hello from embedded Javascript');
</script>
<echo message="End"/>
</target>
</project>
我收到以下错误:
build.xml:5: java.lang.IllegalAccessError: class jdk.nashorn.internal.codegen.types.Type (in unnamed module @0xeafc191) cannot access class jdk.internal.org.objectweb.asm.Type (in module java.base) because module java.base does not export jdk.internal.org.objectweb.asm to unnamed module @0xeafc191
at jdk.nashorn.internal.codegen.types.Type.getInternalName(Type.java:282)
at jdk.nashorn.internal.codegen.CompilerConstants.className(CompilerConstants.java:243)
at jdk.nashorn.internal.codegen.CompilerConstants.staticCallNoLookup(CompilerConstants.java:372)
at jdk.nashorn.internal.codegen.types.BooleanType.<clinit>(BooleanType.java:70)
at jdk.nashorn.internal.codegen.types.Type.<clinit>(Type.java:669)
at jdk.nashorn.internal.codegen.CompilerConstants.className(CompilerConstants.java:243)
at jdk.nashorn.internal.codegen.CompilerConstants.virtualCall(CompilerConstants.java:551)
at jdk.nashorn.internal.codegen.CompilerConstants.virtualCall(CompilerConstants.java:536)
at jdk.nashorn.internal.runtime.ScriptObject.<clinit>(ScriptObject.java:141)
at jdk.nashorn.internal.runtime.Context.newGlobalTrusted(Context.java:819)
at jdk.nashorn.internal.runtime.Context.newGlobal(Context.java:636)
at jdk.nashorn.api.scripting.NashornScriptEngine$2.run(NashornScriptEngine.java:275)
at jdk.nashorn.api.scripting.NashornScriptEngine$2.run(NashornScriptEngine.java:271)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:312)
at jdk.nashorn.api.scripting.NashornScriptEngine.createNashornGlobal(NashornScriptEngine.java:271)
at jdk.nashorn.api.scripting.NashornScriptEngine.<init>(NashornScriptEngine.java:108)
at jdk.nashorn.api.scripting.NashornScriptEngine.<init>(NashornScriptEngine.java:82)
at jdk.nashorn.api.scripting.NashornScriptEngineFactory.getScriptEngine(NashornScriptEngineFactory.java:139)
at java.scripting/javax.script.ScriptEngineManager.getEngineByName(ScriptEngineManager.java:241)
at org.apache.tools.ant.util.optional.JavaxScriptRunner.createEngine(JavaxScriptRunner.java:193)
at org.apache.tools.ant.util.optional.JavaxScriptRunner.evaluateScript(JavaxScriptRunner.java:141)
at org.apache.tools.ant.util.optional.JavaxScriptRunner.executeScript(JavaxScriptRunner.java:82)
at org.apache.tools.ant.taskdefs.optional.Script.execute(Script.java:53)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.Target.execute(Target.java:449)
at org.apache.tools.ant.Target.performTasks(Target.java:470)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1391)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1254)
at org.apache.tools.ant.Main.runBuild(Main.java:830)
at org.apache.tools.ant.Main.startAnt(Main.java:223)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)
使用 ANT 1.8.4 和 ANT 1.10.5 时。
所以我的问题是:我做错了什么,或者这是我应该报告的 Java 16 后续版本中的错误?任何建议的解决方法?