我正在使用Eclipse SCADA框架,该框架使用Nashorn将JavaScript集成到Java中。
Nashorn的一个特性是您可以直接从JavaScript片段调用Java代码。
我已经阅读了一些教程,为了调用你必须使用的java方法:
var MyJavaClass = Java.type('countdown2.test2');
但我收到以下错误:
!ENTRY org.eclipse.scada.vi.ui.draw2d 4 0 2018-05-09 15:45:08.572
!MESSAGE countdown2.test2 cannot be found by org.eclipse.scada.vi.ui.draw2d_0.3.0.v20160226-1536
!STACK 0
java.lang.RuntimeException: java.lang.ClassNotFoundException: countdown2.test2 cannot be found by org.eclipse.scada.vi.ui.draw2d_0.3.0.v20160226-1536
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:397)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:421)
at jdk.nashorn.api.scripting.NashornScriptEngine.access$300(NashornScriptEngine.java:73)
at jdk.nashorn.api.scripting.NashornScriptEngine$3.eval(NashornScriptEngine.java:514)
at org.eclipse.scada.utils.script.ScriptExecutor.executeScript(ScriptExecutor.java:259)
at org.eclipse.scada.utils.script.ScriptExecutor.access$1(ScriptExecutor.java:239)
at org.eclipse.scada.utils.script.ScriptExecutor$3.call(ScriptExecutor.java:295)
at org.eclipse.scada.utils.script.Scripts.executeWithClassLoader(Scripts.java:123)
at org.eclipse.scada.utils.script.ScriptExecutor.execute(ScriptExecutor.java:290)
at org.eclipse.scada.utils.script.ScriptExecutor.execute(ScriptExecutor.java:285)
at org.eclipse.scada.vi.ui.draw2d.SymbolController.runUpdate(SymbolController.java:560)
at org.eclipse.scada.vi.ui.draw2d.SymbolController.handleDataUpdate(SymbolController.java:550)
at org.eclipse.scada.vi.ui.draw2d.SymbolController$2.run(SymbolController.java:503)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4155)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3772)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1127)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1018)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:694)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:606)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at ejemplo.Application.start(Application.java:20)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:669)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:608)
at org.eclipse.equinox.launcher.Main.run(Main.java:1515)
at org.eclipse.equinox.launcher.Main.main(Main.java:1488)
Caused by: java.lang.ClassNotFoundException: countdown2.test2 cannot be found by org.eclipse.scada.vi.ui.draw2d_0.3.0.v20160226-1536
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:439)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:352)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:344)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at jdk.nashorn.internal.runtime.Context.findClass(Context.java:1051)
at jdk.nashorn.internal.objects.NativeJava.simpleType(NativeJava.java:498)
at jdk.nashorn.internal.objects.NativeJava.type(NativeJava.java:322)
at jdk.nashorn.internal.objects.NativeJava.type(NativeJava.java:314)
at jdk.nashorn.internal.objects.NativeJava.type(NativeJava.java:310)
at jdk.nashorn.internal.scripts.Script$Recompilation$23$1510$cilindrovertical.updateValve(cilindrovertical.js:46)
at jdk.nashorn.internal.scripts.Script$2$onUpdate.:program(onUpdate:1)
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:637)
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
... 38 more
我做错了吗?我正在"cilindrovertical.js"
文件中编写JavaScript代码,我正在引用"test2"
文件中的"src"
类。我应该如何编写Java.type代码?
Eclipse Project Explorer
提前感谢您的回答。