views:

323

answers:

3

I wrote my Java application in Eclipse. Now I would like to generate a .jar file which can be run on other systems from the command line. Is there a easy way to do it in Eclipse?

In particular I am wondering what should I do with the jar files of external library that I use (should it be included into my .jar file?).

Moreover, should I generate some manifest files?

ADDED:

I see the window in which I can choose "Extract required libraries into generated JAR" or "Package required libraries into generated JAR" and so on. I select the first option, I specify export destination but "Next" button is not activated yet. What else should I specify. I am offered to launch a configuration but i do not want to. Every configuration is associated with a fixed set of parameters given in the command line and I do not want that.

+5  A: 

Select you project, then Export => Java => Runnable JAR file

You can then choose to extract/package/copy required libraries into your JAR and also select the class, whose main() method should be executed on startup.

Then you can execute the generated jar via: java -jar yourjar.jar

PartlyCloudy
I stack on "extract/package". What it the meaning of these options? Should I "extract" or "package" libraries?
Roman
Package: External jars will remain as jar in the root of your archive.Extract: External jars will be extracted and the class files put/mixed together with your class files.
PartlyCloudy
A: 

I don't know of any way to create a self-contained jar file from within eclipse if your program depends on other jar-files.

I suggest you have a look at http://one-jar.sourceforge.net/

aioobe
A: 

When you go to Export => Java => Runnable JAR file, You said "Next" button is not activated yet, You don't have to press the next button because you can just press finish, If you don't want the Lauch Configuration, You can manually edit the manifest file later. If you have external libraries you can chose one of the options they give you, extract/package/copy required libraries into jar file