How to Create a .exe File From a Java Program?
Last Updated :
15 Nov, 2023
In this article, we will learn how to create a .exe file from a Java program. Java is a platform-independent language, which works on the philosophy of "write Once, Run Anywhere". It simply means that if we write a Java program, we can run it on any device that has a JVM(Java Virtual Machine). Now if we want to share the Java application standalone for the windows, then we need the ".exe" file. In this article first, we will create a Java program then we will see the various methods to create a ".exe" file from that file.
Java applications are generally shared and distributed as ".jar" files. These files contain all the required files, to run a .jar file we must need the JVM installed on the system we are trying to run. So what is the need for the ".exe" file, If a system does not have a JVM then we need a ".exe" file to run our application.
Steps to create a .exe file
Before creating the ".exe" file, we need to create a Java program, So let's create a simple Java program that says hello world. Follow these steps to create and run the Java program:
Step 1: Create a file hello.java
Step 2: Open the file in any IDE, and write the following code.
Java
import java.util.Scanner;
public class Hello {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Hello, World!");
System.out.println("Press Enter to exit...");
scanner.nextLine();
scanner.close();
}
}
Step 3: Now to compile this program run the following command:
javac hello.java
Step 4: Now there will generate a file called hello.java which means that you successfully compiles, to run this program, run the following command:
java hello
Step 5: See the output in the command prompt:

Creating .exe file
There are several methods to convert a Java application to an .exe file. Some popular methods are listed and explained below.
Now before creating the .exe file, there is one file that we need the .jar file, now when you initially create a java program it generally contains the .java and .class files, use the following commands to create the .jar file.
jar cvfe Hello.jar Hello Hello.class
Now there will be a .jar file, and we will be using that .jar file to create the .exe file using various tools that are discussed below.
1. Using JSmooth
File checks to if a suitable JVM is installed in the system or not and runs the app.
Step 1: Go to the official website of Jsmooth and download the application.
Step 2: Install the application on the system.
Step 3: Open the application, go to sell, auction, and choose the console wrapper.

Step 4: Now go to the executable and give the file name that you want to create.

Step 5: Now go to the application first give the class name and choose the location of the .jar file

Step 6: Here choose the minimum JRE version, go for 1.5.0

Step 7: Now click on the Gear icon on the top and the .exe file will be created in chosen directory.

Step 8: Now double-click on the .exe file that was created, and see the output.

2. Using Jar2Exe
This application is also used to create the .exe file from the .jar file. Follow the given steps to use this application to create the .exe file of the Java application.
Step 1: Go to the official website Jar2Exe and download the application in the system.
Step 2: Open the application, select the path of the .jar file, select the JRE version go for 1.5, and click next for the system choose windows, and click next.

Step 3: Here choose the console application and click next.

Step 4: Here enter the class name of the Java application and click next.
Step 5: Now .exe file will be created and you can run and see the output by double-clicking the .exe file.

3. Creation using Maven
To create an executable jar file for the maven projects we must have to install the maven in the system. Ensure the maven installation by running the following command.
mvn --version
Now follow the following steps to create the executable jar file. Note that we are using VS code as IDE.
Step 1: Create a maven project, use Ctrl + Shift + P, and choose the create maven project for the basic project use the maven-archtype-quickstart option as shown in the image.

Step 2: After the project creation it will create the file directory and there will be a pom.xml file for the project configuration. On that file add the following code inside the Plugins according to your project name.
XML
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.test.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
Step 3: Now it's time to build the jar file. run the following command in the terminal.
nvm package
After this command, on the file directory, there will be a folder that will generate a named target, and inside that folder, there will be the .jar file. We can run this file and check by using the following command
java -jar filename.jar
Output:

Conclusion
In conclusion, we have seen two applications that help us to create a .exe file, and it's pretty easy to use them. Now we can use the methods that are described above, to make the .exe file from the jar file. Follow those method steps and create the .exe file.
Similar Reads
How to Create Jar File for Java Project in Eclipse?
Java programmers already know about what is a jar file if you are new then first understand what is a jar file. Once you are completed your project in Eclipse the next task is to create a runnable version of your project. Eclipse support only exporting the JAR (.jar) file, not the Executable (.exe)
3 min read
How to create a user defined javap tool?
What is a javap tool? The javap tool is used to get the information of any class or interface. The javap command (also known as the Java Disassembler) disassembles one or more class files. Its output depends on the options used ("-c" or "-verbose" for byte code and byte code along with innards info,
4 min read
Create a Temporary File in Java
In Java, we can create a temporary file using an existing method known as File.createTempFile() method which creates a new empty file on the specified directory. The createTempFile() function creates a temporary file in a given directory (if the directory is not mentioned then a default directory is
4 min read
How to Check a File or Directory Exists in Java?
One of the most frequent tasks carried out by a file system in an operating system is checking the existence of a directory or a file. In the form of library functions, most programming languages provide some level of file system accessibility. You will discover how to test an existing file or direc
1 min read
How to Execute a .class File in Java?
A Java Class file is a compiled java file. It is compiled by the Java compiler into bytecode to be executed by the Java Virtual Machine. Step #1: Compile the .java File Open Terminal (Mac) or Command Prompt (Windows). Navigate to the folder containing the java file and type the following command to
1 min read
How to Create a Java Docker Container?
Java is one of the most popular languages and supports many enterprise applications. Running Java on local machines requires the installation of Java IDE, Java JDK, and Java JRE and the setting of paths and environment variables. This might seem like a hefty task especially if you just want to run a
9 min read
How to Create a File in CMD
We all know that one can easily create files using GUI options, but what if you can use a faster way to create files through the command-line interface? This is not a necessary but useful skill for anyone working with Windows. Whether you're automating tasks, working on scripts, or preferring using
5 min read
Create a Single Executable from a Python Project
Creating a single executable from a Python project is a useful way to distribute your application without requiring users to install Python or any dependencies. This is especially important for users who may not be familiar with Python or who need a simple way to run your application on their system
3 min read
How to Create an Executable JAR with Maven?
The Maven is a powerful build automation tool primarily used for java program projects. And It simplifies that build process, dependency management and project configuration through a standard project object model which means POM file. This file is heart of the Maven Project and Build Automation. In
4 min read
Compilation and Execution of a Java Program
Java, being a platform-independent programming language, doesn't work on the one-step compilation. Instead, it involves a two-step execution, first through an OS-independent compiler; and second, in a virtual machine (JVM) which is custom-built for every operating system. The two principal stages ar
5 min read