Create Windows Executable (.exe) for Java Application

Launch4j is a cross-platform tool for wrapping Java applications distributed as jars in lightweight Windows native executable files. In this post, we will learn making such an executable file for a demo java application.

Step1 ) Create a java application

I am creating a very basic java class which simply displays a frame and some text on it. It also has the main() method which will start the application.

package com.howtodoinjava;

import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Label;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JDialog;

public class ApplicationMain extends JDialog 
	private static final long serialVersionUID = 1L;
	public ApplicationMain() 
		//Create a frame
		Frame f = new Frame();
		f.setSize(500, 300);
		//Prepare font
		Font font = new Font( "SansSerif", Font.PLAIN, 22 );
		//Write something
		Label label = new Label("Launch4j Maven Demo with");

		//Make visible
		f.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
	public static void main(final String[] args) 
		new ApplicationMain();

Step 2) Create maven file with launch4j configured in it

I have created a pom file for packaging the application as .exe file. If you feel something unclear, drop a comment.

<project xmlns="" xmlns:xsi=""
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">

Step 3) Create .exe file

To make the exe file for above java program, run maven command:

mvn package

Above command will create the “howtodoinjava.exe ” file in your project’s target folder. Double click on .exe file will open the window like this.

Launch4j maven demo to create java executable
Launch4j maven demo to create java executable


If you want to download source code of above application, click on below given download link.

Sourcecode Download

Happy Learning !!

Was this post helpful?

Join 7000+ Awesome Developers

Get the latest updates from industry, awesome resources, blog updates and much more.

* We do not spam !!

21 thoughts on “Create Windows Executable (.exe) for Java Application”

  1. Hi Lokesh,

    I have 3 three questions:

    1) Under how to give relative path because if i just give img.ico it wont find i have placed icon under icon folder how can i specify relative path to image apart from hard coding path name like C:\… Since it wont work in others system.

    2) Where we can see error log generated?

    3) I have created Eclipse Plugin Project and given main class as packagename.Activator getting error as
    “A Java Exception has occured” to report full error log i need answer for 2nd question.


  2. There is a small mistake in the pom.xml file:


    should be replaced with

  3. Hi,
    I’m developing the desktop application in java 7 , 3 classes are there in my application. i created the java .exe file by using launch 4j but it is showing error as ” java exception has occured”

  4. Its working now…

    I am able to make my jar as exe…
    But I have new issue.

    My Jar was reading config properties(kept outside of jar)… how to do it in exe…..where to set classpath in exe so that it can read

  5. Failing because of :-
    net.sf.launch4j.BuilderException: Application jar doesn’t exist.

  6. I executed your example without any issue….but when I am trying to use same approach for my project code….then getting following error (Any Idea why failing…):

    [INFO] Platform-specific work directory already exists: C:\Users\vikas\.m2\repo
    net.sf.launch4j.BuilderException: Application jar doesn’t exist.
    at com.akathist.maven.plugins.launch4j.Launch4jMojo.execute(Launch4jMojo
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPlugi
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLi
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(Defau
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHan
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmen
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLi
    at org.apache.maven.DefaultMaven.doExecute(
    at org.apache.maven.DefaultMaven.execute(
    at org.apache.maven.cli.MavenCli.main(
    at org.apache.maven.cli.compat.CompatibleMain.main(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    at java.lang.reflect.Method.invoke(

  7. I just copied above code and rant it, but i am getting below error
    [ERROR] Failed to execute goal com.akathist.maven.plugins.launch4j:launch4j-mave
    n-plugin:1.5.1:launch4j (l4j-clui) on project JavaExeDemo: Failed to build the e
    xecutable; please verify your configuration. Icon doesn’t exist. -> [Help 1]


Leave a Comment


A blog about Java and related technologies, the best practices, algorithms, and interview questions.