Runnable .jar在Ubuntu上工作但不在Windows上工作

时间:2015-03-14 12:49:57

标签: java swing jar

这就是在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)

针对引发的例外显示的MemoryClassLoaderMemoryFileManager类来自此处: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
谢谢!

1 个答案:

答案 0 :(得分:2)

{p} compilerMemoryClassLoader.<init>(MemoryClassLoader.java:12)中为空。 如果没有任何编译器,ToolProvider.getSystemJavaCompiler()将返回null。

好像你确实需要安装JDK来运行它(或者至少是类路径上的tools.jar): ToolProvider.getSystemJavaCompiler() returns null - usable with only JRE installed?