labs / tiddlers / content / labs / lab13 / _Labs_13_Packaging a Release of the
At the moment you are pretty reliant on NetBeans to run your application.  In this section we will show you how to create an executable package that does not need NetBeans.  Note that this relates to the topics covered in the release engineering lectures (lectures 23 & 24) --- we are showing you the bare minimum that you need to know to create a deployable build in this section.  We will focus on the product administration system from milestone 2 --- deploying web services/applications is another topic entirely that is covered in INFO303 (semester 1).

We are already using the `application` Gradle plugin that allows us to create executable Java applications.  You can see where this is declared in `plugins` section at the top of the `build.gradle` file.

1. The first thing that we need to do is to make Gradle generate compiled code that is compatible with Java 8.  Java 8 is still very prevalent, and is currently the default version on the Linux machines in lab 3.27.  Add the following to the bottom of your `build.gradle` file:

   compileJava {
      sourceCompatibility = '1.8'
      targetCompatibility = '1.8'
   Java is mostly backwards compatible (there are some exceptions, but they do not affect us), so code compiled for Java 8 will work on more recent versions of Java.

1. Select the root of the project in the projects pane.

1. In the navigator pane, find the <<menu "Distribution > assembleDist">> Gradle task.  Double click it to execute the task.

1. You can find the distribution in the files pane under <<path "build/distribution">>.  There will be a Zip and a Tar version which are both archives that contain the complete distribution that you can give to your end users.

Let's look at how to use the distribution:

1. Right-click the `distributions` folder and select <<menu "Open in File Manager">>.

1.  Double click the Zip file to open it.

1. Copy and paste the project folder that is inside the Zip file to another location in your home folder.

1. Poke around in the extracted folder.  You will see a large number of JAR files in the `lib` folder.  The `bin` folder contains startup scripts that should work in Windows (the `.bat`) file, or Linux and macOS (the file with no extension).

1. Start H2 if you haven't already done so.  We will discuss how to package/deploy the database at the end of this section.

1.  Try double clicking the Linux startup script.  Sometimes the system file managers are configured to not allow scripts to be executed, so you might need to run the script from the command line.  Right click the background of the file manager and select <<menu "Open Terminal Here">>.  Run the file using:


    You should see your Swing GUI appear since that is the main class that is currently configured as the default (via the `mainClassName` property in `build.gradle`).  NetBeans is not involved here at all.  So long as the user's computer has a recent version of Java (version 8 or better) installed on it, then everything should work fine.

Systems that have a database like our system are a bit more complicated since the database also needs to be packaged and deployed.  How you deal with databases depends on several factors:

* Which DBMS your system is using.  Larger systems like MySQL, Oracle, and Postgres need to be installed on a server and properly configured for the environment and requirements of the system.  Smaller databases like H2 that don't require installation or significant configuration can be packaged along with the application, or packaged separately.

  The H2 packages that we gave you on Blackboard are a reasonable representation of what is needed to deploy and run H2.

* Are multiple clients connecting to the database?  In this case you will need to install the database on a server and configure the clients to use that database.  If not then you may be able to embed the database directly into the application.  H2 can be used in an embedded mode.  Another light-weight database that is often used in an embedded mode is SQLite (

* The database itself either needs to be deployed into the DBMS or created from the schema along with any initial data that needs to be added to the database.  Most DBMSs have mechanism that allows you to send SQL statements to them via scripts, or you can create a small program that can be used to create and propagate the database.  There are many ways to do this including the manual approach that we have been using in INFO202 where we use the management console to interact with the database.

  We did use an automated mechanism to create the testing database in lab 7 by calling the `runScript` command from the database's `INIT` parameter in the JDBC connection string.  We **don't** recommend that you use the `INIT` parameter like this for setting up a production database unless it is guaranteed to be a one-shot operation.  Using the `INIT` parameter to connect to a production database is dangerous since the schema file may include SQL statements that will destroy or contaminate the database.