Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

manually create the jar exe file of your Java program in simple steps

License

NotificationsYou must be signed in to change notification settings

jdevfullstack-tutorials/java-create-jar-exe-file

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

updated 22 April 2022

Hits

Setting The Windows System Environment

  1. Without the compiler added to thePath, you cannot useJava in the Command Prompt.

  2. First, install the latest Java SE from:

    https://www.oracle.com/technetwork/java/javase/downloads/index.html

  3. After that, in your computer, go toSystem Properties, you selectAdvanced System Settings. Or, you can directly search:

    Environment Variables

    but, it is better to go toSystem Properties inControl Panel, because sometimes,coming from search, the computer will not allow you toedit the System Variables.

  4. You should now be at Environment Variables window.At the bottom, you will seeSystem Variables, selectPath, then clickEdit.

  5. You should add there the directory of the Java compiler.Copy and paste that at the last part, but be careful!It contains several information that should not be deleted.

    And, when you don't see the last semicolon;from the last directory, you should add that.Mine is:

    ;C:\Program Files (x86)\Java\jdk1.8.0_144\bin;
  6. To check whether this is successful, openthe Command Prompt and type

    javac

    then hitEnter,if the Command Prompt gives you information,then it is successfully added.

Compiling & Running The Java Source Code Through The Command Prompt

  1. Change the directory to where you put your source code.

  2. But it is better you put your code on the Desktop directory.

  3. If the code is on the Desktop, then open CMD, then type

    cd Desktop

    then hitEnter, this will bring you to the Desktop.

  4. First, you need to compile the Java code in order to run the code.

  5. Typejavac followed by the filename with the filename extension.Example:

    javac MyFirstProgram.java

    then hitEnter.

  6. If this is correct, then it will bring you to the next line.

  7. Then, type

    java MyFirstProgram

    then hitEnter, this will run your code.

  8. Now, you have the class file and the java file. It is readyfor creating the Executable JAr File.

Creating The Executable JAR File

Remember that Java is a high-levelprogramming languageand the creators of this language put somebarrier on direct manipulationof the memory for security reasons,unlike C that has a direct access to memory.

Also, one implication is thatJava should be portableto any OS. Hence, there is the Java Runtime Environmentthat contains the Java Virtual Machineto fulfill such a thing.

With that, creating the standard executable file is somewhat different.Hence, they call it as Executable JAr File.JAr stands for Java Archive.

  1. Given you are done with the compilation,you need to create the manifest file.Within the same directorycreate a text document (.txt),name it asmanifest.txtso that calling the file will not be hard.Open that and type

    Main-Class: MyFirstProgram

    hitEnter twice then save the changes.

    You need to hitEnter twice.Java will fulfilla metadata within the manifest file too.

    Here, I am just using the above example. Of course,if the name of the class file is different,then that should be the name instead ofMyFirstProgram.

  2. Then after that you are now ready to create theExecutable JAr File.

    Open the Command Prompt and change the directory againto where you put your code.Then type

    jar cfm MyFirstProgram.jar manifest.txt MyFirstProgram.class

    then hitEnter.

    If you have multiple class files, then include them too.Again, I'm using the above example for continuity.To test whether this is successful, double click the newExecutable JAr File, and if the program runs, you're done!Happy coding!


Useful Links

https://introcs.cs.princeton.edu/java/85application/jar/jar.html

https://www.javatpoint.com/how-to-make-an-executable-jar-file-in-java

About

manually create the jar exe file of your Java program in simple steps

Topics

Resources

License

Stars

Watchers

Forks


[8]ページ先頭

©2009-2025 Movatter.jp