所以在这种情况下......我尝试从java文件中创建一个类对象(在其上使用方法getDeclaredConstructors),我在库net.openhft库的帮助下加载文件。编译器和行看起来像:Class<?> clazz = CompilerUtils.CACHED_COMPILER.loadFromJava(fileName, IOUtils.toString(new FileReader(file)));
。当我在Intellij中运行应用程序时,它完全正常,但是当我从应用程序中制作一个jar并尝试执行相同操作时,我收到错误消息:
线程中的异常&#34; JavaFX应用程序线程&#34; java.lang.NoClassDefFoundError:net / openhft / compiler / CompilerUtils 在com.company.Modules.ChangeVariableNameModule.storeConstructors(ChangeVariableNameModule.java:530) at com.company.Modules.ChangeVariableNameModule.changeVariableNames(ChangeVariableNameModule.java:85) 在com.company.Obfuscator.obfuscate(Obfuscator.java:53) 在com.company.View $ 7.handle(View.java:242) 在com.company.View $ 7.handle(View.java:210) at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown) 资源) 在com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(未知 资源) 在com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(未知 资源) at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown) 资源) 在com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(未知 资源) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown 资源) 在com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(未知 资源) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown 资源) 在com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(未知 资源) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown 资源) at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source) at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source) 在javafx.event.Event.fireEvent(未知来源) 在javafx.scene.Node.fireEvent(未知来源) 在javafx.scene.control.Button.fire(未知来源) at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(Unknown) 资源) at com.sun.javafx.scene.control.skin.BehaviorSkinBase $ 1.handle(未知 资源) at com.sun.javafx.scene.control.skin.BehaviorSkinBase $ 1.handle(未知 资源) at com.sun.javafx.event.CompositeEventHandler $ NormalEventHandlerRecord.handleBubblingEvent(Unknown 资源) at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown) 资源) 在com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(未知 资源) 在com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(未知 资源) at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown) 资源) 在com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(未知 资源) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown 资源) 在com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(未知 资源) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown 资源) 在com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(未知 资源) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown 资源) at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source) at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source) 在javafx.event.Event.fireEvent(未知来源) 在javafx.scene.Scene $ MouseHandler.process(未知来源) 在javafx.scene.Scene $ MouseHandler.access $ 1500(未知来源) 在javafx.scene.Scene.impl_processMouseEvent(未知来源) 在javafx.scene.Scene $ ScenePeerListener.mouseEvent(未知来源) at com.sun.javafx.tk.quantum.GlassViewEventHandler $ MouseEventNotification.run(Unknown 资源) at com.sun.javafx.tk.quantum.GlassViewEventHandler $ MouseEventNotification.run(Unknown 资源) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda $ handleMouseEvent $ 354(Unknown 资源) at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown) 资源) at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Unknown 资源) at com.sun.glass.ui.View.handleMouseEvent(Unknown Source) at com.sun.glass.ui.View.notifyMouse(Unknown Source) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda $ null $ 148(未知来源) at java.lang.Thread.run(Unknown Source)引起:java.lang.ClassNotFoundException:net.openhft.compiler.CompilerUtils at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher $ AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 52更多
我读了一些关于此异常的内容,我是否必须将类路径设置为我的应用程序所在的位置?如果是的话,是否有可能在java中也这样做? - 也许是Runtime.exec()?
或者有更好的方法吗?我已经尝试了很多方法,但我不知道如何解决这个问题。
感谢您的帮助!