0

I've been looking around for how to create an executable jar file in Windows, and everything I'm getting either involves using MacOS or Linux commands, or Eclipse. Are there any other options?

3 Answers 3

2

Here is your answer:

  1. Start Command Prompt.
  2. Navigate to the folder that holds your class files:
  3. C:>cd \mywork
  4. Set path to include JDK’s bin. For example:
  5. C:\mywork> path c:\Program Files\Java\jdk1.7.0_25\bin;%path%
  6. Compile your class(es):
  7. C:\mywork> javac *.java
  8. Create a manifest file and your jar file:
  9. C:\mywork> echo Main-Class: Craps >manifest.txt
  10. C:\mywork> jar cvfm Craps.jar manifest.txt *.class or C:\mywork> jar cvfe Craps.jar Craps *.class

Test your jar:

  1. C:\mywork> Craps.jar or C:\mywork> java -jar Craps.jar

For more details you can look here.

1
  • The part of this that is actually the answer to your question is the "jar" command. That should come with any distribution of the JDK, regardless of operating system, so it is not a "Linux" command. It's a program that you get with whatever JDK distribution you have installled
    – arcy
    Jun 9, 2016 at 19:30
-1

From Eclipse, Select the project/class, right click, export > java> JAR file. Sometimes export to a jar file may not be able to run, export to 'Runnable JAR file' instead.

Export java class to jar file directly from command line: jar -cvf jarFile.jar jarFileClass.class To create an executable jar file,you need to provide a manifest file and include your Main Class in Manifest.

  1. Create MANIFEST.MF file by using any text editor: Manifest-version: 1.0 Main-Class: HelloWorld
  2. Execute following jar command to create executable jar Java jar -cvfm jarFile.jar MANIFEST.MF jarFileClass.class added manifest

Read more: http://javarevisited.blogspot.com/2012/03/how-to-create-and-execute-jar-file-in.html#ixzz4B73l9pB8

To run a jar file from command line: java -jar jarFile.jar

0
-2

I am using Launch4j in production for 2 years now without single problem on 700+ machines! You can find the full example here, but also, you can build exe file directly from maven with this plugin.

2
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – pczeus
    Jun 10, 2016 at 2:14
  • @pczeus I have provided the link to the full example which is self explanatory, why would I paste the content here? Jun 10, 2016 at 19:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.