Java jar file netbeans

How to Create an Executable Java Jar File in NetBeans

This is a method to create executable java jar files when the program was written in the NetBeans IDE.

Objectives

Prerequisites

  • Requires NetBeans and a general knowledge of how to use it.
  • Expects that a program has already been written and simply needs to create an executable file.

Create Jar File

The tool is finished and now the programs are ready to publish to the SVN directory to expand the usability of USARSim. First make sure the program is debugged and ready to be used by others by creating easy to use configuration files so that the code is easily manipulated without opening the source, editing the code, and then going through this process again. Save all files and set the project with the program as the main project. Do this by right clicking the project in the Projects tab and click “Set as Main Project”, as shown in figure 1. I will be working with the SoundSensorServer Project throughout this tutorial.

Next go up to the File menu and select Project Properties (Your Project Name). In the new window click on Run in the Categories area. Fill out the text fields with the appropriate information, as shown in figure 2.

The Main Class is necessary and all others are optional. If there are any libraries or other jar files that are required to run the program then click on Libraries in the Categories area and add all the appropriate libraries and jar files. Click the ok button and right click on the project over in the project tab and click Clean and Build, as shown in figure 3.

Читайте также:  Sites created with php

In the project folder a new folder dist was created with the executable jar file of the program, see figure 4.

Change the name as you deem necessary, as it will have the name of the project not the individual program. Move it to a new folder in the Tools directory of USARSim and be sure to keep all of the configuration files and any documentation for the individual program together in this new folder.

If you have multiple programs in the same package that must be executable, be sure to remove the jar of the first program to the new folder and change its name before going back to the project properties, selecting run, and changing the Main Class. Otherwise, NetBeans will overwrite the old jar and since the jar file holds the name of the package.

You can either double click this executable jar to run it, or run it in the command line with the command “java –jar filename.jar”, where filename is whatever you called the jar file.

Источник

Оцените статью