Search code examples
javanetbeansdeploymentpackaging

How can I Export my Java Project in Netbeans in Executable(.exe)?


I have completed my project but unable to export in executable form. I'm using Netbeans 12.


Solution

  • Thanks to everyone who wanted to help me.

    I got the solution myself and wanted to help new developers:

    For JDK 14+ with modern IDEs:

    1. Install JDK 14 or later on your system, if it's not already installed.

    2. Open a terminal or command prompt and navigate to the directory containing your Java application and its dependencies.

    3. Build your application using a build tool such as Maven or Gradle. Make sure to specify that you want to create a standalone executable JAR file.

    4. Once your application is built, navigate to the directory containing the JAR file.

    5. Run the jpackage command with the appropriate options to create a native installer for your application. Here is an example command to create a Windows MSI installer:

    Example:

    jpackage --input . --name MyApp --main-jar myapp.jar --type msi
    

    This command assumes that your application JAR file is named "myapp.jar" and that you want to create a Windows MSI installer with the name "MyApp".

    Here are some more examples and options for using jpackage to create native installers:

    Specify an icon for the installer:

    jpackage --input . --name MyApp --main-jar myapp.jar --type msi --icon myicon.ico
    

    Specify an installer splash screen:

    jpackage --input . --name MyApp --main-jar myapp.jar --type pkg --splash splash.png
    

    Include a custom JVM option:

    jpackage --input . --name MyApp --main-jar myapp.jar --type exe --java-options "-Xmx2g"
    

    Set the installation directory

    jpackage --input . --name MyApp --main-jar myapp.jar --type dmg --app-image myapp.dmg --app-image-dir /Applications
    

    Create a ZIP archive instead of an installer

    jpackage --input . --name MyApp --main-jar myapp.jar --type zip
    

    For JDK 8 with NetBeans 8.2: (old but works)

    1. Start an Ant based standard project
    2. Enable native packaging inside Properties->Build->Deployment
    3. Install Inno setup tool for Exe, Wix Toolset for Msi (similar package manager for other OS)
    4. add bin paths of above tools as system environment variables
    5. right click on project and select package as->Exe or MSI

    Screenshot