NetBeans-SCSNI

3.4-Demonstrate the ability to package and distribute a built Java Desktop project for use by another user.

Preparing a JAR File for Deployment Outside the IDE

Whenever you build a standard Java project for which a main class is specified, the IDE automatically copies any JAR files on the project's classpath to the dist/lib folder. The IDE also adds each of the JAR files to the Class-Path element in the application JAR's manifest.mf file. This simplifies running the application outside the IDE.

Though the IDE copies the necessary files to the dist/lib directory automatically, the following special cases should be kept in mind:

  • If two JAR files on the project classpath have the same name, only the first JAR file is copied to the lib folder.
  • If you added a folder of classes or resources to the classpath (as opposed to a JAR file or project), none of the classpath elements are copied to the dist folder.
  • If a library on the project's classpath also has a Class-Path element specified in its manifest, the content of the Class-Path element must be on the project's runtime path.

Running an Application JAR Outside of the IDE

Once you have distributed the archive of your application, the application can be run outside of the IDE from the command line.

To run an application JAR file from the command line:

  1. Navigate to the project's dist folder.
  2. Type the following:
java -jar <jar_name>.jar

When you run the jar command, the JAR tool uses the JAR manifest to determine the application entry point and the paths to the dependent binaries that are specified in the manifest.mf file.         


-- Wagner R. Santos