简体   繁体   English

由netbeans创建的.Jar文件不再在Windows上打开

[英].Jar file, created by netbeans doesn't open anymore on windows

For some reason, my application stopped working when I used "clean and build" at NetBeans and try to run it from dist folder. 出于某种原因,当我在NetBeans中使用“clean and build”并尝试从dist文件夹运行它时,我的应用程序停止工作。 Application used to open from the jar file, but now it only blinks, and even doesn't give any error messages. 应用程序用于从jar文件打开,但现在它只闪烁,甚至不会给出任何错误消息。 Application runs, if I test run it with F6 using NetBeans. 应用程序运行,如果我使用NetBeans测试使用F6运行它。 Jar file is created by NetBeans, so I guess the manifest should be okay. Jar文件是由NetBeans创建的,所以我猜清单应该没问题。

Here's the link for the jar file... 这是 jar文件的链接......

Executing the jar in the terminal gives this exception trace: 在终端中执行jar会产生以下异常跟踪:

Exception in thread "main" java.lang.NullPointerException
    at javax.swing.ImageIcon.<init>(ImageIcon.java:155)
    at tbs.ImageLoader.loadImage(ImageLoader.java:11)
    at tbs.Flag.<init>(Flag.java:21)
    at tbs.Model.<init>(Model.java:58)
    at tbs.GameView.<init>(GameView.java:33)
    at tbs.GUI.<init>(GUI.java:36)
    at tbs.Main.main(Main.java:6)

So it looks like you had something like this here: 所以看起来你有这样的东西:

public Image loadImage(String name) {
   return new ImageIcon(getClass().getResource(name));
}

... and the getResource() method returned null , which caused the ImageIcon constructor to throw the Exception. ...并且getResource()方法返回null ,这导致ImageIcon构造函数抛出异常。

In line 21 of Flag.java you used "images/flagNeutral.png" as the image string, but your jar file contains images/flagneutral.png (inside the tbs directory). 在Flag.java的第21行中,您使用"images/flagNeutral.png"作为图像字符串,但您的jar文件包含images/flagneutral.png (在tbs目录中)。 See the difference? 看到不同?

If it worked on your local system outside of the jar, you are using a case-insensitive file system there. 如果它在jar之外的本地系统上运行,那么您在那里使用不区分大小写的文件系统。 (Windows or Mac?) In the jar, as well as over HTTP and on "real" file systems, the URLs are case sensitive, which means you have to name the resource precisely as the file is named. (Windows或Mac?)在jar,以及HTTP和“真实”文件系统上,URL都区分大小写,这意味着您必须在命名文件时精确命名资源。


And yeah, normally you should have at least tried your program yourself, and posted the stack trace as well as the relevant code lines. 是的,通常你应该至少自己尝试过你的程序,并发布堆栈跟踪以及相关的代码行。

Typical error when you don't define the main class before clean and run. 在清理和运行之前未定义主类时的典型错误。

Click right on the project -> properties ->run section ->define the main class. 单击项目右键 - >属性 - >运行部分 - >定义主类。

  • There may be a lib folder in the dist directory. dist目录中可能有一个lib文件夹。 If so, it contains jar files for any libraries you included. 如果是这样,它包含您包含的任何库的jar文件。 Make sure that is the case. 确保是这种情况。 You need to distribute the jar as well as the entire lib folder and store both in the same folder just like Netbeans creates them. 您需要分发jar以及整个lib文件夹,并将它们存储在同一文件夹中,就像Netbeans创建它们一样。
  • I am hoping you have created a Java application project and not a Java Class library project. 我希望你创建了一个Java应用程序项目而不是Java类库项目。
  • You can check if the main-class attribute and any library paths are added properly when you "clean and build" the project. 在“清理和构建”项目时,可以检查是否正确添加了main-class属性和任何库路径。
  • You can run it like java -jar tbs.jar and see the response. 您可以像java -jar tbs.jar一样运行它并查看响应。

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

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