Now that I've created my application, how do I get it to work outside of the IDE?

Some users wonder, "How do I distribute this application to other users so they can run it, without having to give them the whole IDE as well?"

A Java Archive, more commonly known as JAR file, aggregates your project files into one file. Software developers use .jar files to distribute Java classes, including libraries associated metadata, to their customers.

JAR files are platform-independent and can be executed on Windows, Mac OS, Linux and UNIX. Similarly, Java Web Applications are distributed as WAR file (Web Archive), and Enterprise applications as EAR file (Enterprise Archive).

Java SE: Creating a standard JAR file in NetBeans

Every time you Clean and Build your project, the IDE automatically creates a distributable JAR file in the "dist" directory.

  • Open the Files window and open your project's node to see the generated directories.
  • Additionally needed JAR libraries are stored in the dist/lib/ directory.
  • You run your project from the command line using java -jar YourProject.jar
  • Tip: Some operating systems can be configured to run JAR files by double clicking them.
  • To package the project, ZIP up the dist folder (including the lib folder!), and distribute the ZIP file.

Troubleshooting tip: If this fails and the Output window says that no dist/lib directory was created, make sure that all the libraries you link to are JAR files, and not directories of classes.

Java EE and Web Apps: Creating EAR and WAR files in NetBeans

Similarly for Java Web Application projects, NetBeans creates a distributable WAR file in the dist directory.

For Enterprise Applications:

  1. To create an EAR file, start with a new empty Java Enterprise project.
  • In the New Java Enterprise Project wizard, uncheck the boxes to create EJB and Web submodules.
  1. Add your existing web app projects etc to the Enterprise project:
    1. In the Project window, open the required web and EJB projects.
    2. Right-click the Enterprise Project node, and choose Add Java EE module.
  2. Clean, Build and Deploy the Enterprise project. The distributable EAR file is created in the dist directory.

Advanced: Custom single JAR files

If you must have your whole application in one single file (for example for publication on the Java Store), follow this quick tutorial to learn how to configure the build script to Combine JAR Files Into a Single JAR File.

Advanced: Custom single JAR files with native dynamic libraries

The above methods are all meant for Java projects that do not require any native dynamic libraries (.dll, .dylib, .so files).

If your project depends on native libraries, and you cannot be certain that your users will have them installed, then you set up a custom solution in the build script. One example for a custom solution is One-JAR, which is described in the Packaging A Distributable Java App tutorial.

See also:

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo