简体   繁体   中英

Exporting JAR from Eclipse

I've created a SWT application using eclipse. In the application I make use of Images with in the project. Now I build the jar file and run it in the command line I get the following error:

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.

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. For example make a folder called "Images". Then exporting a Runnable Jar should work.

That will get you the Images into your Jar file. Once it's there you will need to retrieve it using the method "getResourceAsStream". If you need help with that there are numerous good answers, here is one, Getting images from a .jar file .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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