Possible Duplicate:
How can I convert my java program to an .exe file ?
I'm trying to export a program written in Java 6 to a JAR file.
My project contains one Java library from the Internet and some Java source files. When I create the JAR file, the classpath should be set by default and the end-user should be able to run the project directly from either the command prompt or some other source.
My goal is to export everything to a JAR file, if that's possible. Also, the program output should be given at the command prompt.
How can I export my program in this way?
You need to write a META-INF/MANIFEST.MF file for this; the file should sit within the jar file you're distributing (i.e., the one that people use with java -jar). Here's an example for a recent "project" I wrote:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Created-By: 11.3-b02 (Sun Microsystems Inc.)
Main-Class: com.hedgee.simonsays.Main
Class-Path: lib/libthrift.jar
The main fields to care about are Main-Class (which specifies which class to look for your main method), and Class-Path (which specifies the external jar files you're using).
You can use Jsmooth http://jsmooth.sourceforge.net/ to bundle your java code to make an executable.
I have had good experiences with two different approaches:
1) Use the fatjar plugin with eclipse to create a single jar file with all the jars you need embedded (uses a custom classloader). This creates a clickable jar file (if it is a GUI program). If you need console output for this Jar wrap it with jsmooth as described by Bhushan.
2) Use the "Export -> Runnable Jar" in Eclipse 3.5 Milestone 6 with the "copy dependent libraries to a subfolder" option to create an ordinary runnable jar with a proper manifest referencing the dependent jar files (which are put in a subfolder). This works very well if you want a solution not using any tricks, but it is a bit hard to script.
来源:https://stackoverflow.com/questions/743029/how-can-i-get-an-executable-file-of-a-java-program