Configuring the GlassFish server

The GlassFish 4 server bundled with NetBeans is automatically configured the first time you run the project. This means any required resources are set up dynamically based on the current state of the project. All such properties are copied to the glassfish-resources.xml file in the setup directory, as shown in the following screenshot:

Configuring the GlassFish server

The glassfish-resources.xml file was modified during the database reverse engineering process to include the database connection pool and JDBC resources required by JPA. As a result, the contents of this file define the required GlassFish connection pool details.

It is important to understand that this file is used by NetBeans to dynamically configure the GlassFish server assigned to the project. In a real-world situation, the GlassFish server is configured by administrators and deploying a web application is done either from the command line or through the GlassFish administration console. You will not be deploying your application through NetBeans in a normal enterprise environment and it is hence very useful to have a fundamental understanding of how GlassFish is configured from first principals. This section is dedicated to configuring the GlassFish server connection pool for use with 3T. Although this is not strictly required to run 3T on NetBeans, we strongly recommend you take the time to configure your GlassFish server fully via the following steps.

This will ensure you understand what is required to configure a GlassFish server on a different physical server for running the 3T application.

  1. The first step in configuring your GlassFish server is to perform a Clean and Build:
    Configuring the GlassFish server
  2. When the build is complete, navigate to target/lib as shown in the following screenshot to view the JAR files required by your project:
    Configuring the GlassFish server
  3. Open a file explorer window (Windows Explorer or OS X Finder) to navigate to this directory and copy the mysql-connector-java-5.1.26.jar file to your GlassFish domain libs directory, as shown in the following screenshot:
    Configuring the GlassFish server

Renaming the setup directory

The setup directory, located at src/main/, contains the glassfish-resources.xml file and should be renamed to ensure NetBeans does not dynamically configure GlassFish with these properties. We suggest renaming the directory to setup-original.

Starting the GlassFish server in NetBeans

Navigate to the Services tab; by right-clicking on the GlassFish Server 4.0 node, select Start as shown in the following screenshot:

Starting the GlassFish server in NetBeans

You should see server output at the bottom of the NetBeans IDE and the GlassFish Server 4.0 node reload. You can now right-click on the GlassFish Server 4.0 node and select View Domain Admin Console:

Starting the GlassFish server in NetBeans

This will start your default browser and load the Domain Admin Console.

Configuring the JDBC connection pool

This section will use the GlassFish admin console to configure the JDBC connection pool and JDBC resource required by the 3T application.

  1. Open the Resources node and navigate to the JDBC Connection Pools tab:
    Configuring the JDBC connection pool

    Note

    You may see a connection pool named mysql_task_time_tracker_rootPool or something similar, as shown in the preceding screenshot. This was created by NetBeans during a previous run using the properties specified in the glassfish-resources.xml file. The remaining section may be skipped if you wish to continue using this connection pool. We recommend you delete this entry and continue to follow these steps to understand how to configure a GlassFish connection pool.

  2. Click on the New button and enter the following details before clicking on the Next button:
    Configuring the JDBC connection pool
  3. The next screen looks daunting but only a few entries are required. Scroll all the way down until you can view the Additional Properties section:
    Configuring the JDBC connection pool
  4. There are many properties here! Thankfully only a few are required unless you are familiar with MySQL database administration. You may safely delete all the listed properties to keep the configuration simple, and then enter the following properties that correspond to the original glassfish-resources.xml file:
    Configuring the JDBC connection pool
  5. The basic fields that are required are URL, User, and Password. Saving these settings will return you to the JDBC Connection Pools screen:
    Configuring the JDBC connection pool
  6. Click on the 3TPool name to open the settings again and click on the Ping button to test the connection. You should now see the following result:
    Configuring the JDBC connection pool

Configuring the JDBC resource

The final step is to create a JDBC Resource. Click on this node to display the configured resources:

Configuring the JDBC resource

Click on the New… button and enter the following details:

Configuring the JDBC resource

The JNDI Name must be the same as the <jta-data-source> property defined in the persistence.xml file and is hence set to jdbc/tasktimetracker. Click on the OK button to save the resource configuration. The refreshed node should now show the newly created resource.

You have now finished configuring the GlassFish JDBC settings.

..................Content has been hidden....................

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