user2999870
user2999870

Reputation: 375

How to run my a Java program as an executable .jar file?

I was wondering how can I turn my program (which I am currently running from Eclipse) into an executable file?

This will make it more feasible as people with JRE can just access it by clicking on a single file.

Any help would be appreciated. Thank you.

Upvotes: 0

Views: 374

Answers (2)

Gaurav Kumar
Gaurav Kumar

Reputation: 1091

You may create this as a maven project and then simply run mvn clean package and the jar will be created in target directory.

Upvotes: 1

Hazim
Hazim

Reputation: 1451

  1. Compile your java code
  2. Create a manifest.txt file.
  3. Specifiy the main class in the manifest file like: Main-Class: com.example.Main
  4. Create a jar by adding the manifest.txt and required .class files: jar cvfm myJar.jar manifest.txt *.class

Note: make sure to add .class files, not .java files.

Upvotes: 1

Related Questions