简体   繁体   English

可运行的.jar可在Ubuntu上运行,但不能在Windows上运行

[英]Runnable .jar working on Ubuntu but not Windows

This is how pressing the submit button from the .jar run from cmd looks like on Windows: 这是在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)

The MemoryClassLoader and MemoryFileManager classes that appear for the raised exception are from here: https://sites.google.com/site/malenkov/java/081217 针对引发的异常而出现的MemoryClassLoaderMemoryFileManager类来自以下位置: https : //sites.google.com/site/malenkov/java/081217
Specific lines are: 具体行是:
Line 12 in MemoryClassLoader : MemoryClassLoader第12行:

private final MemoryFileManager manager = new MemoryFileManager(this.compiler);

Line 15 in MemoryClassLoader : MemoryClassLoader第15行:

this(Collections.singletonMap(classname, filecontent));

and Line 15 in MemoryFileManager : MemoryFileManager第15 MemoryFileManager

super(compiler.getStandardFileManager(null, null, null));  

Seeing that the program runs correctly from Eclipse and on Ubuntu I'm guessing it has something to do with paths to the javax.tools imports? 看到程序可以从Eclipse以及在Ubuntu上正确运行,我猜它与javax.tools导入的路径有关吗? At a certain point in the project I remember making eclipse move from using JRE to using JDK because of errors regarding to those same classes. 在项目的某个时刻,我记得因为与那些相同类有关的错误,使Eclipse从使用JRE迁移到了使用JDK。 What do I need to do to make it run on Windows? 我需要做些什么才能使其在Windows上运行? I'm sorry if it's a stupid question of if it's obvious :p 很抱歉,如果这是一个愚蠢的问题,是否很明显:p
Thank you! 谢谢!

compiler is null in MemoryClassLoader.<init>(MemoryClassLoader.java:12) . MemoryClassLoader.<init>(MemoryClassLoader.java:12) compiler为null。 ToolProvider.getSystemJavaCompiler() returns null if there isn't any compiler. 如果没有任何编译器,则ToolProvider.getSystemJavaCompiler()返回null。

Seems like you indeed need to have JDK installed to run this (or at least the tools.jar on the classpath): ToolProvider.getSystemJavaCompiler() returns null - usable with only JRE installed? 似乎确实需要安装JDK才能运行此文件(或至少在类路径上的tools.jar): ToolProvider.getSystemJavaCompiler()返回null-仅可用于JRE吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM