简体   繁体   English

从Eclipse导出JAR

[英]Exporting JAR from Eclipse

I've created a SWT application using eclipse. 我已经使用Eclipse创建了SWT应用程序。 In the application I make use of Images with in the project. 在应用程序中,我在项目中使用Images with。 Now I build the jar file and run it in the command line I get the following error: 现在,我构建了jar文件并在命令行中运行它,出现以下错误:

Caused by: java.io.FileNotFoundException: Images\Back.png (The system cannot fin
d the path specified)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(Unknown Source)
        at java.io.FileInputStream.<init>(Unknown Source)
        at org.eclipse.swt.internal.Compatibility.newFileInputStream(Unknown Sou
rce)

Now I can see that the program cant read my Image but I would like to ask how to I include the Images in the jar file for everything to run smoothly. 现在,我可以看到该程序无法读取我的图像,但是我想问一下如何将图像包含在jar文件中,以使所有程序都能顺利运行。

Right click on your project, choose export. 右键单击您的项目,选择导出。

Export -> Java -> Jar file

Choose the resources you would like to export, then click Finish. 选择您要导出的资源,然后单击“完成”。

If you need a runnable jar, just make sure the files are part of your project. 如果需要可运行的jar,只需确保文件是项目的一部分即可。 For example make a folder called "Images". 例如,创建一个名为“ Images”的文件夹。 Then exporting a Runnable Jar should work. 然后导出一个Runnable Jar应该可以了。

That will get you the Images into your Jar file. 这将使图像进入Jar文件。 Once it's there you will need to retrieve it using the method "getResourceAsStream". 一旦到达该位置,您将需要使用“ getResourceAsStream”方法来检索它。 If you need help with that there are numerous good answers, here is one, Getting images from a .jar file . 如果您需要很多帮助,这里有一个很好的答案,一个是从.jar文件获取图像

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

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