0

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.

user2999870
  • 345
  • 4
  • 12
  • 2
    Possible duplicate of [How do I create executable Java program?](http://stackoverflow.com/questions/804466/how-do-i-create-executable-java-program) – haihui Mar 01 '16 at 07:01
  • set the environment settings of the os, and add a manifest file to your jar, pointing to the class which contains the main method – Stultuske Mar 01 '16 at 07:02
  • Check out this article: https://docs.oracle.com/javase/tutorial/deployment/jar/ – software_writer Mar 01 '16 at 07:02
  • Use http://launch4j.sourceforge.net/ – Aakash Mar 01 '16 at 07:03
  • 1
    Possible duplicate of [How can I convert my Java program to an .exe file?](http://stackoverflow.com/questions/147181/how-can-i-convert-my-java-program-to-an-exe-file) – rve Mar 01 '16 at 07:11

2 Answers2

1
  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.

Hazim
  • 1,405
  • 1
  • 11
  • 24
  • don't forget the step "add Java to your environment settings" – Stultuske Mar 01 '16 at 07:14
  • Actually, @Stultuske, that is not strictly necessary. You can always use the full pathname of the `java` command, and the CLASSPATH variable is ignored when you launch an executable JAR using `-jar`. – Stephen C Mar 01 '16 at 07:37
  • @StephenC which is assuming it will only run on your machine, but if it's a jar that is to be distributed, and you have no idea where Java is installed ... – Stultuske Mar 01 '16 at 07:40
  • But the person who installed it knows where it was installed. But either way, it is the person who installs Java who would be setting the PATH variable ... not the person who is creating the JAR file. – Stephen C Mar 01 '16 at 08:48
1

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

Gaurav Kumar
  • 1,091
  • 13
  • 31