Make Java Executable

Make Java ExecutableI’ve been asked many times to show how to make a java program executable. It is actually very easy to make Java executable on any computer.

The main tool you’ll use on a PC is the Command Line or DOS Prompt. To find it click Start and in the box at the bottom type cmd.exe. If you’re on a MAC, just search for terminal in the search box.

I walk through everything in the tutorial video below. If you need any other help, everything follows in text format after the video.

If you like videos like this, it helps others if you tell Google [googleplusone]

Share if you think others may like this

Make Java Executable

This works if you’re on a MAC, or a PC. Just follow these steps to make an executable java file:

  • Create a source and classes folder and save your source code in the source directory
  • Open either your Command Line (PC), or Terminal (MAC)
  • Change to your source directory ( cd /source )
  • Execute this command javac -d ../classes *.java
  • Change to your classes directory ( cd ../classes )
  • You can now execute your code with this command java nameOfMainProgramFile

Make Executable Jar

  • Do everything above
  • Change to your classes directory ( cd ../classes )
  • Make a text file named manifest.txt in a text editor
  • Put the following line in manifest: Main-Class: nameOfMainProgramFile
  • Hit enter at the end of the line above and save manifest.txt in your classes folder
  • Type this into your terminal jar -cvmf manifest.txt nameOfMainProgramFile.jar *.class
  • Now you can execute your program by double clicking on it

12 Responses to “Make Java Executable”

  1. Puneet says:

    Hi Derek. I really like your Java videos. very simple to understand. I have a question. From this Jar file, how can I make a executable(.exe) file(as .jar runs only in Java environment)so that I can share that with our people to use.

  2. Billy says:

    I love your Java tutorials and was wondering if you could cover how to move the Menubar content from a JFrame to the Mac OX finder bar to help make it appear more native.

    Great job on these videos… they have really helped me out big time.

    • admin says:

      Thank you very much 🙂 To use the Mac menu bar do this System.setProperty(“apple.laf.useScreenMenuBar”, “true”);

      Many more Java videos are in the works. I’ll be making videos that pertain to Java for at least another year

  3. Mac joe says:

    thank you for short tutorial, currently i am trying to learn JAVA programming under Mac OS

  4. Shaan says:

    Hi, i’ve been trying to make my java projects executable. i’m on a pc. whn i am trying to compline my codes in command line i am getting the following error:

    “javac is not recognized as an internal or external command, operable program or batch file.”

    love your videos by the way 🙂


    • Derek Banas says:

      You probably need to add it to your path. You’ll have to locate where javac is on your computer

      1. Right click on “My computer” on your desktop and choose ‘Properties’
      2. Choose Advanced tab
      3. Click on Environment Variables
      4. find the PATH variable and ‘Edit’ it’s value to include
      ;c:\program files\Java\jdk1.6.0_05\bin (Or, the location of your java bin directory)

      • Anonymous says:

        wow I can’t believe you replied thats so nice of you, I have a mac though and I’m not sure how to get to that option on one, is there another place to go?

        • Derek Banas says:

          I do my best to reply to every comment. I apologize, but I’m not sure what your original question was though. It is hard for me to search back through comment history because you posted anonymously. If you type in a fake name I can find you better if you don’t want to use your real name. Of course if you repost your question i’ll try to help 🙂

  5. Tatenda says:

    Thanks for your tutorials, really appreciated. Tell me, I’ve scoured the ENTIRE internet (slight exaggeration there) looking for how to deploy a jar file with the associated text files and image icons etc… How do you do that? My project compiles but with these errors

Leave a Reply to Derek Banas Cancel reply

Your email address will not be published.