56

I'm trying to export a program in Eclipse to a jar file.

In my project I have added some pictures and PDF:s. When I'm exporting to jar file, it seems that only the main has been compiled and exported.

My will is to export everything to a jar file if it's possible, because then I want to convert it to an extraditable file, like .exe-file.

But how?

Lii
  • 11,553
  • 8
  • 64
  • 88
Adis
  • 804
  • 1
  • 9
  • 15
  • please refer this link https://www.cs.utexas.edu/~scottm/cs307/handouts/Eclipse%20Help/jarInEclipse.htm – madhu Aug 04 '15 at 11:09

4 Answers4

62

No need for external plugins. In the Export JAR dialog, make sure you select all the necessary resources you want to export. By default, there should be no problem exporting other resource files as well (pictures, configuration files, etc...), see screenshot below. JAR Export Dialog

Matan Itzhak
  • 2,702
  • 3
  • 16
  • 35
Yuval Adam
  • 161,610
  • 92
  • 305
  • 395
  • 2
    Correct, assuming the necessary resources don't include other jar files. – seanhodges Jan 08 '09 at 11:29
  • In my project/program, Im using a database that is created when I shut down the program. So I cant pack the database file. When I follow you direction and try to start the jar-file I get the message: Failed to load Main-Class manifest attrebute from ..._path_... – Adis Jan 08 '09 at 12:10
  • 2
    @Pedro - yes, the JAR can be executable, in the next view in the wizard you can choose the main class. – Yuval Adam Jan 08 '09 at 14:09
  • Could I save list of selected resources permanently with project? – plaidshirt Jul 12 '18 at 12:41
10

Go to file->export->JAR file, there you may select "Export generated class files and sources" and make sure that your project is selected, and all folder under there are also! Good luck!

5

FatJar can help you in this case.

In addition to the"Export as Jar" function which is included to Eclipse the Plug-In bundles all dependent JARs together into one executable jar.
The Plug-In adds the Entry "Build Fat Jar" to the Context-Menu of Java-projects

This is useful if your final exported jar includes other external jars.

If you have Ganymede, the Export Jar dialog is enough to export your resources from your project.

After Ganymede, you have:

Export Jar

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
2

One more option is WinRun4J. There is an Eclipse Plugin for WinRun4J that allows you to export your application as a single executable with necessary jars/classes embedded.

(full disclosure: I work on this project)

Peter Smith
  • 753
  • 6
  • 7