Making executable Java Desktop Applications

After creating a Java Desktop Application, adding Frames and Containers, adding event listeners, and customizing the application, the only thing left is creating an executable. And making a lot of money (of course!).

Getting ready

It is necessary to have the sources of a Java Desktop Database Application in your NetBeans project folder.

It is necessary to have Java DB up and running. If unsure how to do this, please refer to Chapter 4, Setting up Apache Derby/Java DB.

The recipe, Creating a Java Desktop Database Application, would be of great help in understanding why the design and components listed here are presented in this manner.

How to do it...

With the Java Desktop Database Application open:

  1. Right-click on the project name, in our case DesktopApplicationDB, and select Properties.
  2. Click on Libraries and select the Run tab.
  3. Click on the Add Library... button.
  4. Add the following libraries: Beans Binding, Swing Application Framework, and TopLink Essentials, then click Add Library.
  5. Then click OK.
  6. Again, right-click on the project name, DesktopApplicationDB, and select Clean and Build.
How to do it...

The output window will show the path in which the JAR file was placed.

To distribute the application, simply compress the application in the desired format - ZIP and RAR are the most popular - and distribute it.

How it works...

When the Clean and Build task is executed, NetBeans generates the JAR file and automatically copies all the necessary libraries to the lib folder.

Here is a list of the libraries contained in lib folder, as shown in the next screenshot:

How it works...

There's more...

How to execute and view the contents of JAR files.

Executing the JAR file

The IDE already gives, through the output window, all the required information to perform this task, but in case you missed it, here it goes:

Under Linux:

java -jar "<USER_DIRECTORY>/NetBeansProjects/DesktopApplicationDB/dist/DesktopApplicationDB.jar"

Under Windows:

The same java jar command from Linux can be used, pay attention to the different file delimiter present in windows.

Contents of the JAR file

Inside the JAR file, you will find that much of the work that the developer was once required to execute manually is now handled by the IDE.

Folder structure of the JAR file is as follows:

Contents of the JAR file
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.233.26