Pack or convert .java file into .exe

Saturday, 19th August 2017

 



This tutorial covers how to convert or pack Java class file(s) into an exe file or program. This tutorial does not covers how to do programming in Java language. This tutorial uses JSmooth software to convert or pack Java class file into an exe file or program.

Requirements:-

  1. Basic understanding of Java programming
  2. Any version of Windows operating system (preferable Windows 7 and above)
  3. Your favorite editor such as notepad++, geany, atom, vim etc.
  4. JDK installed and PATH environment variable configured or set
  5. Download JSmooth from here and install it.
  6. Your favorite logo, recommended size 512 by 512 pixels (optional)

For the demonstration, we are going to write basic java program (hello world in Java).

Step 1: Open your favorite editor, and write a java program to display "hello world" (without quotes) in console.
You can copy the program from below, paste it and save it with the name HelloWorld.java.

						
	/* Java program to print Hello world... */

	public class HelloWorld {
		public static void main(String[] args) {
				System.out.println("Hello world...");
		}
	}

						
					

Step 2: Open a command prompt and nvaigate to the directory where you saved the program. Compile the program from command prompt.

						
	javac HelloWorld.java
						
					

You can execute the program in the command prompt to check whether the program is working correctly or not. Use the following command to execute it.

						
	java HelloWorld
						
					

Step 3: Now the class file must be converted into a jar file and then this jar file is packed into an exe. Using following command convert HelloWorld.class file into a jar.

						
	jar cvfe HelloWorld.jar HelloWorld HelloWorld.class
						
					

The enire command is divided into 5 parts.

jar command which initiates the process.

cvfe command-line arguments.

c - create new archive (effectively new jar file)
v - generate verbose output
f - specify archive filename (output jar filename)
e - specify application entry point. This option is required if the manifest file is not explicitely specified in the command. This argument instruct to create a one.

HelloWorld.jar output archive name or output jar filename.

HelloWorld Name of the class containing the main method. This class name is added to the newly created manifest file. This information in the manifest file specifies the entry point of the application.

HelloWorld.class Name of the class to be added to the jar. If you have more than one class file, specify them using the * notation (i.e., *.class).

If the command is successful, it'll display output as above. This output indicate the name of the output archive or jar name list of classes added.

Step 4: Open Jsmooth


Step 5: Click on skeleton option in the left menu then choose console wrapper in the skeleton selection section. Scroll down and check press key. This will ensure that console is open even after completion of program execution.


Step 6: Click on Application option in the left menu then in Main class specify the class name containing the main method. In Embedded jar settings check Use an embedded jar and select the jar file.


Step 7: Click on Executable option in the left menu then in Executable settings specify the full output path including the name of the output executable file with .exe.extension. In Executale icon select an icon.


Step 8: Click on JVM selection option in the lefe menu and specify the minimum and maximum version of JVM required in Java versions settings section.


Step 9: Go to Project menu and click on compile. It will ask to save the current JSmooth project, save it then it will display compilation dialogue window. The executeable file is available at the location specified in step 7.


to check whether the executable is created without any errors, open a command prompt navigate to the directory where the output file is stored, enter the file name with .exe extension.


Note: After successfully completing this tutorial you can tweak other settings to create awesome applications.

Have anything to add or need help, just ping

Remember "Sharing is Caring"

Managed WordPress Hosting Static New

Subscribe

Thank You...

request failed! Contact admin.

Search Your Domain Name Here

WordPress Hosting Offer July
black-seal-1

Connect...