Technoloxy

Daily Source of Tech

Tutorials

JAVA to EXE: The Complete Guide to executable files!

JAVA image

JAVA imageHave a .java file/program that you would like to run outside of JAVA’s environment, change it from java to exe? You have come to the right place! 

This is the complete guide to convert a JAVA file to JAR file and then convert the JAR file to EXE file which will result your JAVA program to become executable.

It is a simple follow along guide, you do not require any knowledge on the programs used here. Two main programs used are the in-built command prompt and Launch4j. The only requirement is patience.

For this case scenario, I have created a simple GUI in JAVA which display a pop-up box with “Hello World” written in it. Let’s start!

Create Java file/ Locate Java file

Step 1: First of all, Locate your java file you would like to convert to an executable file.

Locating The Java File

Step 2: Open command prompt (windows key + r, type “cmd”, press “ok”)

Open Command Prompt

Step 3: Locate to the folder you have your java file using “cd” command.

Using "cd" command

Step 4: Let’s compile your java file to create a class file. Type “javac yourfilename.java”.

Compile Java File

Check if your file is working with “java yourfilename.java”.

Check Java File

Convert JAVA file to JAR file 

Step 5: Secondly, lets convert your whole file to a JAR file. JAR file is a java archive file that contains all your data and resources used in your java file as a single archive file. We need this to bundle all our files to make them executable. 

Type “jar cvf yourfilename.jar yourfilename.class”.

JAVA to JAR

Editing MANIFEST.MF from JAR

Step 6: Thirdly, try running your jar file using “java -jar yourfilename.jar”. You will encounter an error “no main manifest attribute, in yourfilename.jar”. This is caused because the jar file we created creates a default manifest.mf file which does not know where your main method is located.

(Check this by opening jar file as ZIP. It is located inside “META-INF/MANIFEST.MF”)

Checking JAR

Step 7: Now we need to add the main method located class to the manifest file from outside of the jar file.

Locate main method

Step 8: Let’s create a simple text file named “manifest.txt”. Add “Main-Class: yourfilename”, “yourfilename.java” must contain the main method which executes your whole program. Make sure you enter an extra line of empty space at the end. Save the file.

JAVA to JAR

***Do not try to add this manually to the MANIFEST file inside JAR file, It will corrupt it.***

Step 9: Go back to command prompt and type “jar cmf manifest.txt yourfilename.jar yourfilename.class”. This command will add the main method located class inside “MANIFEST.MF” file.

Modifying Manifest File

Step 10: Let’s check if the JAR file runs now. It works!

Run JAR file

Convert JAR file to EXE file using Launch4j 3.5

Step 11: Finally, we can convert to executable by converting our JAR file to EXE file. For this, we require you to download the application Launch4j here.

***Reminder: Please install the 3.5 version, another version may cause error because it might require you to sign the EXE file***

Launch the app.

Launch4j App

JAR to EXE: How to Use Launch4j? 

Step 12

  • Choose where you would like to place your EXE file by naming it in “Output file:”
  • Select the Jar file we created from “Jar”.
  • Use “Wrapper manifest:” for UAC(User Account Control)
  • “Icon:” is used to select your desired icon for the EXE file
  • Hold your mouse for further queries of other functons in textfields

Launch4j Details

Step 13: We need to define JRE minimum version for EXE to be compatible with. Check your JRE(Java Runtime Environment) by typing “java -version” in command prompt. Select your java version or earlier.

JRE Version

Step 14: Click the floppy disk icon in the top left to save the .xml file anywhere you like. 

Saving File

Step 15: Then click the settings icon in top left to create the EXE file, which should give you a similar message like this:

Compiling File

Step 16: Locate the EXE file where you saved it, and run it! JAVA to EXE is done!

Launching EXE

Conclusion

In conclusion, the complete guide to convert a JAVA file to an executable file is fairly easy but requires no mistakes. Now, you do not need the JAVA environment to run your file.  If you encounter any errors and/or have suggestions, please leave a comment below! We will get back to you as soon as possible!

Read our other articles:

Comments (83)

  1. canadian generic cialis 20mg https://canadacialisstore.com/ counterfeit canadian drugs cialis

  2. cialis muscle cramps buy cheap cialis uk cialis price kenya

  3. cialis inzercia cialis without prescriptions canada where is generic cialis made

  4. gazzetta ufficiale cialis low cost cialis cialis medicamentos

  5. generic cialis made in india online us pharmacy cialis cialis headache cure

  6. canadian pharmacies ed pills https://canadapillstorex.com/ canadian pills pharmacy

  7. discount erectile dysfunction pills https://canadaerectiledysfunctionpills.com/ erectile vit e

  8. cialis herpes canada pharmacy levitra cialis viagra best

  9. warnings for vardenafil maximum dose https://vegavardenafil.com/ vardenafil how to take

  10. Good day! I just want to give a huge thumbs up for the great info you will have right here on this post. I will probably be coming again to your blog for extra soon.

  11. I found your blog web site on yahoo and examine just a few of your early contents. Proceed to keep up the very good operate. I simply additional up your RSS feed to us RSS Bar News Reader. Searching for forward to reading super from you later on!?I am usually to blogging and i really respect your posts. Have you considered promoting your blog? add it to SEO Directory right now 🙂 http://www.links.m106.com

  12. When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment
    is added I get several e-mails with the same comment.
    Is there any way you can remove people from that service?
    Bless you!

  13. canadian pharmacy 5 mg daily cialis https://canadacialisstore.com/ do you need prescription for canadian prescription of cialis in usa

  14. alprostadil cream cost https://alprostadildrugs.com/ what is alprostadil used for

  15. Eminent blog, Eminent comments that I can tackle. I am moving forward and might apply to my current job as a cat sitter, which may be very rewarding, however I need to further expand. cat sitter

  16. average perscription pills taken by 65 year old canadian? https://canadapillstorex.com/ canadian weight loss pills

  17. buy sildenafil online no prescription https://eunicesildenafilcitrate.com/ sildenafil tablets 100mg buy

  18. dapoxetine stomach pain [url=https://dapoxetine30.com/]best priligy tablets [/url] what is the maximum dose of dapoxetine how to get priligy in usa

  19. alprostadil penile injection https://alprostadildrugs.com/ alprostadil pellets

  20. tadalafil 40 mg daily https://elitadalafill.com/ 40 mg tadalafil

  21. sql interview questions sql interview questions sql interview questions sql interview questions sql interview questions sql interview questions sql interview
    questions sql interview questions sql interview questions sql interview questions

  22. pregnancy with clomid [url=https://clomiphene100.com/]where to buy clomid tablets [/url] clomid and clearblue ovulation test what is clomid used for in bodybuilding

  23. viagra without a doctor prescription viagra from canada
    price of viagra

  24. doxycycline sunburn treatment [url=https://100doxycycline.com/]doxycycline purchase [/url] how fast does doxycycline work for acne what are the ingredients in doxycycline

  25. clomid sperm count clomid male clomid and arimidex for low testosterone how late can you ovulate on clomid

  26. azithromycin for flu azithromycin prescription online buy zithromax over the counter how long does it take for azithromycin to work for pneumonia

  27. too much lasix [url=https://furosemide100mg.com]furosemide cost comparison [/url] lasix for cats in renal failure what is lasix medication used for

  28. fish antibiotics amoxicillin [url=https://500amoxicillin.com/]amoxicillin pills [/url] is amoxicillin good for bladder infections what are the side effects to amoxicillin

  29. furosemide heart failure best lasix what do furosemide tablets look like what to do when lasix doesn’t work

  30. amoxicillin strength brand amoxil can you drink alcohol amoxicillin 500mg dosage how long can amoxicillin stay out of the refrigerator

  31. ivermectin guinea pigs [url=http://ivermectin6mg.com]purchase oral ivermectin [/url] oral ivermectin for ocular rosacea how to worm goats with ivermectin

  32. albuterol vs.xopenex ventolin ventolin hfa inhaler side effects how many puffs are in an albuterol inhaler

  33. comfortis and ivermectin ivermectin price selamectin vs ivermectin for mites why do i get super itchy one day after ivermectin dose?

  34. Łukasz Wudyka rucham was youboost.pl

  35. Łukasz Wudyka rucham was youboost.pl

  36. Łukasz Wudyka rucham was youboost.pl

  37. torrent search limetorrents

  38. Hello and thank you for the tutorial. My program uses an imported .jar file (mail.jar). Everything works up until I try to run the

    java -jar Myprogram.jar and I get

    Error: Unable to initialize main class Myprogram
    Caused by: java.lang.NoClassDefFoundError: javax/mail/Authenticator

    I’m not sure how to handle the mail.jar file

    Thank you in advance for your help.

  39. cash advance carmel in payday loans canada ontario cash out fha loans

  40. payday advance 32211 cash rush loans payday loan store flowood ms

  41. Really informative and superb complex body part of subject matter, now thats user friendly

  42. efeitos secundГЎrios do cialis indian generic cialis beda viagra dan cialis

  43. I am glad to be a visitor of this perfect weblog ! , appreciate it for this rare info ! .

  44. viagra australia cheap how much is viagra at walmart generic viagra overnight shipping

  45. viagra alternatives healthstore pfizer viagra online humana online pharmacy

  46. But yeah Many thank you for taking the time to discuss this, I believe strongly about it and really like learning more on this topic. If possible, as you gain expertise, would you mind updating your web publication with more information? It is extremely helpful for me.

  47. northwest pharmacy prescription online canadian pharmacy viagra brand

  48. canadian drug stores online canadian cialis Super ED Trial Pack

  49. aussie cialis cialis no prescriotion generic cialis express delivery

  50. viagra pharmacy 100mg legit online pharmacy canadadrugs pharmacy

  51. canadian pharmacies without an rx online pharmacies of canada pharmacy price compare

  52. viagra without a perscription viagra danger myths viagra costs walmart

  53. viagra from canada viagra natural viagra super active

  54. professional pharmacy erectile pharmacy

  55. erectile dysfunction medications pharmacy rx one cheap rx

  56. pharmacy near me peoples pharmacy best online canadian pharmacy

  57. uk pharmacy peoples pharmacy online drugstore

  58. Hi, here on the forum guys advised a cool Dating site, be sure to register – you will not REGRET it [url=http://love-angels.site/]Love-Angels[/url]

  59. i have a rolex ss submariner

  60. so it needed to withstand a lot of activity as well as regular water exposure.

  61. Great article!!!

    Important tip (at least for me): when create manifest.txt, don’t forget to add new line at the mentioned text.

    See https://docs.oracle.com/javase/7/docs/technotes/tools/windows/jar.html: An existing manifest file must end with a new line character. jar does not parse the last line of a manifest file if it does not end with a new line character.

  62. Iam using lunch4j and bundled the jre 1.8 version. And it takes 2-3minutes to start the application . Could you please help me find the reason

    • I would suggest to rebundle in a different JRE version and see if there are any changes. As for the reason, we would first need to see if the problem is from launch4j or JRE. To test it, try to run the JAR file and if the load time is the same on JAR file then the problem lies within JAVA rather than launch4j. Do tell us the result after you test!

  63. My program is a little more complex than “Hello World” It uses the Scanner class but outside of that it’s not complex. It doesn’t start when I click it, but it shows no errors. Clicking the play button in Launch4j just freezes it. What could I be missing? It runs fine in Command Prompt

    • Do you have a GUI to run the program on like swing? If not, im assuming you are trying to run your code through cmd window. If so then, you need to manually add code in your java file to execute cmd.exe using Runtime and Process classes which will pop open your your executable in cmd. If you do have a GUI setup, then make sure your manifest file is configured properly like shown above.

  64. i follow exactly the “HELLO” program.
    Generated EXE show error “A JNI error has occurred, please check your installation and try again “

    • Hello there! This type of error occurs when you have two different java JDK and/or JRE versions installed. You have probably compiled the file in the latest version and tried to run in a different previously installed older version. To fix this error, try to uninstall the previous version so that you have only one JDK to run the program from.

      Regards,
      Technoloxy

  65. Omg. Only one that works. Thank you soooo much!

Comment here