这就是在 Windows 上从 cmd 运行的 .jar 中按下提交按钮的样子:
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.
C:\Users\Vlad>java -jar run.jar
java.lang.NullPointerException
at MemoryFileManager.<init>(MemoryFileManager.java:15)
at MemoryClassLoader.<init>(MemoryClassLoader.java:12)
at MemoryClassLoader.<init>(MemoryClassLoader.java:15)
at Main.run(Main.java:130)
at GUI$2.mouseClicked(GUI.java:185)
at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Sour
ce)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Sour
ce)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Sour
ce)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
针对引发的异常出现的 MemoryClassLoader
和 MemoryFileManager
类来自此处:https://sites.google.com/site/malenkov/java/081217
具体线路为:
MemoryClassLoader
第 12 行:
private final MemoryFileManager manager = new MemoryFileManager(this.compiler);
MemoryClassLoader 中的第 15 行:
this(Collections.singletonMap(classname, filecontent));
和MemoryFileManager
中的第15行:
super(compiler.getStandardFileManager(null, null, null));
看到该程序在 Eclipse 和 Ubuntu 上正确运行,我猜测它与 javax.tools 导入的路径有关?在项目的某个时刻,我记得让 eclipse 从使用 JRE 转向使用 JDK,因为与这些相同的类有关的错误。我需要做什么才能让它在 Windows 上运行?如果这是一个是否显而易见的愚蠢问题,我很抱歉:p
谢谢!
最佳答案
compiler
MemoryClassLoader.<init>(MemoryClassLoader.java:12)
中为空。
ToolProvider.getSystemJavaCompiler()如果没有任何编译器,则返回 null。
看起来你确实需要安装 JDK 才能运行它(或者至少是类路径上的tools.jar): ToolProvider.getSystemJavaCompiler() returns null - usable with only JRE installed?
关于java - 可运行的 .jar 可在 Ubuntu 上运行,但不能在 Windows 上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29049129/