Technology Programming

How to Create an Executable Java File

    • 1). Click "Start," then "Run," then type "cmd" and press "Enter." Click on the newly opened Command window.

    • 2). Type this command into the Command window:

      cd "\javaProject"

      Replace "\javaProject" with the name of the folder containing your class files.

    • 3). Create a file named "projectManifest.mf" with a text editor. Include the following line in the file:

      Main-class:mainClass

      Replace "mainClass" by the name of the class containing the "main" method in your application. By convention, the execution of any Java application starts by invoking that method. Save the file and exit the editor.

    • 4). Create a single, executable jar by typing into the Command window:

      jar -c -m projectManifest.mf -f javaExec.jar mainClass.class anotherClass1.class anotherClass2.class

      Replace "anotherClass1," "anotherClass2," ... with the file names of all other class files your application has. Press "Enter." The jar (Java archive) tool will generate an executable file named "javaExec.jar". Moving that file will move the whole application; opening that file will start the application.

Leave a reply