简体   繁体   English

Eclipse Java-程序可以在Eclipse中运行,但不能作为可运行的jar

[英]Eclipse Java - Program works in eclipse but not as runnable jar

I am trying to export my program as a runnable jar. 我试图将我的程序导出为可运行的jar。 The program works absolutely fine inside of eclipse but it does not work as a runnable jar. 该程序在eclipse内绝对可以正常运行,但不能作为可运行的jar。 I am using 3 other jar files as referenced jars so I can use audio, and I think this might be the problem. 我正在使用其他3个jar文件作为参考jar,因此我可以使用音频,我认为这可能是问题所在。 The runnable jar launches but its just an all white window and the program doesn't start. 可运行的jar启动,但它只是一个全白的窗口,程序无法启动。

I am clicking on my project and then right clicking and selecting "Export", then I am selecting the "runnable jar" option. 我单击我的项目,然后右键单击并选择“导出”,然后选择“可运行的jar”选项。 I have tried creating the jar using all three of the options dealing with referenced libraries. 我尝试使用处理引用库的所有三个选项来创建jar。

  • Extract required libraries into generated jar 将所需的库提取到生成的jar中
  • Package required libraries into generated jar 将所需的库打包到生成的jar中
  • Copy required libraries into a sub-folder next to the generated jar 将所需的库复制到生成的jar旁边的子文件夹中

None of these options result in a working program. 这些选项均不能使程序正常运行。 Hopefully you guys can help me! 希望你们能帮助我!


Edit 编辑
yes there is an error: 是的,有一个错误:

Exception in thread "Thread 2" java.lang.IllegalArgumentException: input == null! 
  at javax.imageio.ImageIO.read 
  at main.BufferedImageLoader.loadImage<BufferedImageLoader.java:36>|
  at main.LoadScreen.<init><LoadScreen.java:38> at main.Engine.run<Engine.java:248> 
  at java.lang.Thread.run 

You're getting the images as files when you need to get them as resources. 当您需要将图像作为资源时,会将图像作为文件获取。 This is a common problem, one that generates a lot of similar questions on this site. 这是一个常见问题,在此站点上会产生很多类似的问题。 Get your class loader or class and use it to getResource(...) to get your images. 获取您的类加载器或类,并将其用于getResource(...)以获取图像。

ie,

  BufferedImage westImg = ImageIO.read(getClass()
        .getResource("/images/img01.jpg"));

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

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