We have created a native windows application!Īs said earlier by default it gets installed in C:/Program Files directory. Now go to any path in the command prompt and enter helloworld: Now let’s try to execute this exe file through command prompt from any path in Windows machine.įor this to happen, add the path of the exe to the ‘PATH’ environment variable of your machine: Go into the folder and click on helloworld.exe: It gets installed in the default C:/Program Files directory:
Now let’s install the application using the exe file created. STEP 4: Install the exe file on a Windows machine Here is the screenshot of running the jar and jpackage commands: It took me a while to realise this was needed (Else application won’t be launched when you click on the installed exe) –win-console means windows console need to be enabled – Command line and Java swing applications need this to be enabled. main-jar helloworld.jar -main-class -win-consoleįollowing –name is the name of the exe fileįollowing –input (.) is the name of the directory which contains the jar file and other inputs (in this case the current directory)įollowing –main-jar is the name of the jar which contains the class to be runįollowing –main-class is the name of the class which is to be run. In the same path where I ran ‘jar’ command I ran the below jpackage command: jpackage -name helloworld -input. If you double click the jar file you get the same output: STEP 3: Use ‘jpackage’ tool to convert the jar file to exeĪs a prerequisite to run jpackage tool to generate a exe file, you need to install Wix Toolset (suggested by Java) from here. To know more about generating jar files refer here : ( Generating jar) Manifest.txt contains meta data about the jar (what is the path of the main class etc)Ĭom is the directory (inside HelloWorld folder) which contains the Main class Helloworld.jar is the name of the jar file to generate I navigated inside it and ran the below jar command: jar cfm helloworld.jar manifest.txt com On building the project the classes got generated in out/production folder ( I am using IntelliJ): G:\projects\fullstackdeveloperblog\spring\springboot\HelloWorld\out\productionĪ new folder named HelloWorld got generated in the above directory. Now let’s convert this project into a jar fileīelow is the path where I have created the Java application: G:\projects\fullstackdeveloperblog\spring\springboot\HelloWorld\ On running this, I get the below output: JOptionPane.showMessageDialog(null, "Hello World", "A Windows Application", JOptionPane.INFORMATION_MESSAGE) I created a Java application with a single file which opens up a message box with the message “Hello World”. STEP 4: Install the exe file on a Windows machine STEP 1: Create the java application : STEP 3: Use ‘jpackage’ tool to convert the jar file to exe STEP 2: Use ‘jar’ tool to generate a jar file Then let’s install the application in a Windows machine. Let’s create a simple Java application which displays the message “Hello World” in a message box and convert it into an exe file. Java again removed the tool in Java 11 version and brought it back in Java 14. No need to install Java in the client machine anymore! These files can then be used to install a native Windows Application. Java 8 came up with jpackage tool which can be used to create. Java itself didn’t provide this facility for a long time. Or you can use third party applications to convert the java application to an exe installation. The application can be launched by running the jar. Traditionally, you need to first install java in that machine and then copy the jar. You want to install this jar in another machine. Let’s say you have created a Java application and packaged it into a jar.