Export a Java Project in Eclipse Neon to Executable JAR with Manifest

This post shows how to Export a Java Project in Eclipse Neon to a JAR file. If the JAR (Java Archive) file contains classes with main methods that have a signature public static void main(String[] args), the Java application can then be executed with the java command.

Export a Java Project in Eclipse Neon

  • Using the Java Perspective, right-click on the Java Project node in the Package Explorer to open its context menu.
Eclipse Neon - View Java Project in Package Explorer and Export to JAR File
  • Select Export and select the JAR file export wizard under the Java node and click Next.
Eclipse Neon - View Dialog to Select an Export Wizard and select JAR file
  • On the JAR File Specification form, set the export destination for the JAR file and click Finish.
Eclipse Neon - Complete JAR File Specification Form and Export a Java Project in Eclipse Neon to JAR File
  • The JAR file, here named JARExportTest.jar is now available in the specified directory.
Eclipse Neon - View Export Destination Containing JAR File on File System

Run the JAR File with the Java Command

  • In this example, the JAR file contains one Java class with one main method:
package com.pgx.java;

public class HelloWorld {

  public static void main(String[] args) {
    // TODO Auto-generated method stub
    String[] words = new String[] {"Hello ", "World", "!"};
    for (String s : words) {
  • Open a terminal on Mac OS or open the command prompt on Windows and go to the JAR file location.
MyMac:Java Admin$ pwd
MyMac:Java Admin$ ls -lha *Export*.jar
-rw-r--r--  1 Admin  1368638373   1.7K Jan 13 16:18 JARExportTest.jar
MyMac:Java Admin$ 
  • The HelloWorld main class can be executed with the following command:
java -cp JARExportTest.jar com.pgx.java.HelloWorld
  • The output is shown in the console:
MyMac:Java Admin$ java -cp JARExportTest.jar com.pgx.java.HelloWorld

Hello World! 

Create a JAR Manifest File in Eclipse Neon

  • Above, the class HelloWorld containing the main method to execute is explicitly given in the java command.
  • Alternatively, a Manifest file can be used to specify an application’s entry point.
  • When exporting the JAR file, select Next on the JAR File Specification form.
Eclipse Neon - Complete JAR File Specification Form and Use Advanced Options
  • Click Next again on the JAR Packaging Options form.
Eclipse Neon - Complete JAR Packaging Options Form
  • The next form will show the JAR Manifest Specification options.
Eclipse Neon - Complete JAR Manifest Specification Form
  • Check Save the manifest in the workspace and use the Browse button to set a location.
  • Select the Main class, here it is HelloWorld using the Browse button.
  • Finally, click in Finish to export the Java project to a JAR file that also contains a manifest file.
  • The manifest file is automatically generated and included in the Java project in Eclipse Neon.
Eclipse Neon - View JAR Manifest File Contents
  • The JAR file can now be executed without specifying a main method. The java command will pick the one provided in the manifest file. Make sure to use the option -jar instead of -cp.
java -jar JARExportTest.jar
MyMac:Java Admin$ java -jar JARExportTest.jar

Hello World! 

Related Posts

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.