Create a Java Executable with Eclipse

Creating java executable in eclipse

Go to file->export->runnable jar and select the class which contains the main method.

Setting .JAR File Association

Normally, the installation program for the Java 2 Runtime Environment will register a default file association so that .JAR files will execute with 'JAVAW -JAR' by double-clicking any .JAR file. If this does not happen, or it somehow gets changed, then manually setting the association for *.JAR files may be needed.

  1. Open the Windows Explorer, from the Tools select 'Folder Options...'
  2. Click the File Types tab, scroll down and select JAR File type.
  3. Press the Advanced button.
  4. In the Edit File Type dialog box, select open in Actions box and click Edit...
  5. Press the Browse button and navigate to the location the Java interpreter javaw.exe.
  6. In the Application used to perform action field, needs to display something similar to "C:\Program Files\Java\j2re1.4.2_04\bin\javaw.exe" -jar "%1" %* then press the OK buttons until all the dialogs are closed.

Now you should be able to launch any *.JAR program by double-clicking it.

This step by step guid was taken from: http://windowstipoftheday.blogspot.com/2005/10/setting-jar-file-association.html

Create executable Jar file under Eclipse

To create a new runnable JAR file in the workbench:

  1. From the menu bar's File menu, select Export.
  2. Expand the Java node and select Runnable JAR file. Click Next.
  3. In the Runnable JAR File
    Specification page, select a 'Java Application' launch configuration
    to use to create a runnable JAR.
  4. In the Export destination field, either type or click Browse to
    select a location for the JAR file.
  5. Select an appropriate library handling strategy.
  6. Optionally, you can also create an ANT script to quickly regenerate
    a previously created runnable JAR file.

Create a java executable with Eclipse

You need to create an executable JAR file. Steps will follow shortly.

Right click on the project and select JAR file under Export.

Sample Image

Enter the path where you want it to be saved. The example here is of Windows. Change according to your platform.

Sample Image

Click Next.

Sample Image

Edit the Main Class field by browsing and selecting the location of your class that contains the main method.

Sample Image

Run it

To run the JAR file, open up a shell or command prompt and execute the following command:

java -jar path/to/test.jar

How to generate executable of java project in eclipse

I recommend launch4j to create executables from JAR files.



Related Topics



Leave a reply



Submit