Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an executable JAR file?

I have a program which consists of two simple Java Swing files.

How do I make an executable JAR file for my program?

like image 747
Reuben Avatar asked Mar 10 '11 10:03

Reuben


People also ask

How do I create an executable JAR file in Windows 10?

In that case, right-click on the file, select open with and choose the app that is suitable for opening the JAR file. To run it directly in the Java Runtime Environment, go to program files and click on the Java folder. Then go to jre1. 8.0_211 and open the bin to select java.exe.

What is an executable JAR file?

A Java Archive, or JAR file, contains all of the various components that make up a self-contained, executable Java application, deployable Java applet or, most commonly, a Java library to which any Java Runtime Environment can link.

How do I create an executable JAR file in Linux?

To create an executable jar file, you can use the following syntax: This syntax can be used from the command line if you are in the directory that contains the application directory structure. The -cfm argument will let you create a jar with -c, specify the name of the jar with -f and specify edits to the MANIFEST.MF with -m.

How to create an executable JAR file from a folder [duplicate]?

how to create an executable jar file from an folder [duplicate] 1 open command prompt. 2 navigate to directory where MyApp is placed using cd. 3 execute command jar cvf MyApp.jar MyApp EDIT ( To make this jar executable:) create a file named MANIFEST.MF and put it in META-INF ...

How to create an executable jar from a manifest file?

Place the compiled output class files (JarExample.class,JarExample$1.class) and the manifest file in the same folder. In the command prompt, go to the folder where your files placed, and create the jar using jar command. For example (if you name your manifest file as jexample.mf) It will create executable jarexample.jar.

How do I create a JAR file in Visual Studio?

Compile your classes. To make a jar, you also need to create a Manifest File ( MANIFEST.MF ). Place the compiled output class files (JarExample.class,JarExample$1.class) and the manifest file in the same folder. In the command prompt, go to the folder where your files placed, and create the jar using jar command.


2 Answers

A jar file is simply a file containing a collection of java files. To make a jar file executable, you need to specify where the main Class is in the jar file. Example code would be as follows.

public class JarExample {      public static void main(String[] args) {         javax.swing.SwingUtilities.invokeLater(new Runnable() {             public void run() {                 // your logic here             }         });     } } 

Compile your classes. To make a jar, you also need to create a Manifest File (MANIFEST.MF). For example,

Manifest-Version: 1.0 Main-Class: JarExample 

Place the compiled output class files (JarExample.class,JarExample$1.class) and the manifest file in the same folder. In the command prompt, go to the folder where your files placed, and create the jar using jar command. For example (if you name your manifest file as jexample.mf)

jar cfm jarexample.jar jexample.mf *.class 

It will create executable jarexample.jar.

like image 187
isurusndr Avatar answered Oct 09 '22 06:10

isurusndr


In Eclipse you can do it simply as follows :

Right click on your Java Project and select Export.

Select Java -> Runnable JAR file -> Next.

Select the Launch Configuration and choose project file as your Main class

Select the Destination folder where you would like to save it and click Finish.

like image 45
Twinscode Avatar answered Oct 09 '22 07:10

Twinscode