Build Java Application as Executable JAR

Q

How to build a Java application as an executable JAR file? I want to use the "java -jar" command to launch the application.

✍: FYIcenter

A

The first step to build your own JavaWS/JNLP application is to build it as an executable JAR file as shown in this tutorial:

1. Create your Java application, HelloJavaWs.java:

// Copyright (c) FYIcenter.com
import javax.swing.*;

public class HelloJavaWs {
   public static void main(String[] args) throws Exception {
      JFrame frame = new JFrame("Hello JavaWS!");
    frame.setBounds(100,100,350,150);
      frame.setVisible(true);
   }
}

2. Compile and test it:

>\fyicenter\jdk-1.8.0\bin\javac HelloJavaWs.java

>\fyicenter\jdk-1.8.0\bin\java HelloJavaWs
   (You see a new application window named as "Hello JavaWS!")

3. Create a manifest file, META-INF\MANIFEST.MF, with two lines:

Main-Class: HelloJavaWs

4. Build the executable JAR file, HelloJavaWs.jar:

>\fyicenter\jdk-1.8.0\bin\jar -cvf HelloJavaWs.jar HelloJavaWs.class
added manifest
adding: HelloJavaWs.class(in = 477) (out= 316)(deflated 33%)

>\fyicenter\jdk-1.8.0\bin\jar -uvmf META-INF\MANIFEST.MF HelloJavaWs.jar
updated manifest

5. Test the executable JAR file, HelloJavaWs.jar:

>\fyicenter\jdk-1.8.0\bin\java -jar HelloJavaWs.jar
   (You see a new application window named as "Hello JavaWS!")

Now your application is ready to be deployed with JavaWS and JNLP. See the next tutorial on a JNLP file for the application.

 

Create JNLP File for Java Application

Building Your Own JavaWS and JNLP Application

Building Your Own JavaWS and JNLP Application

⇑⇑ FAQ for JavaWS (Java Web Start)

2017-12-26, 1123🔥, 0💬