NetBeans
Deploying web-applications
We have created a web-application. Our Java Application server is GlassFish server. We now want to deploy it on this server. .How should we proceed?
a. Clean and Build you project. Carry WAR file and MySQL Java connector file to place where application is to be installed.
b. At remote site, install GlassFish server and NetBeans.
c. Use NetBeans to create a GlassFish domain in the user-account of your choice.
d. Copy MySQL connector jar file to lib folder of domain.
e. Start GlassFish server and open Admin Console.
f. Create desired Connection Pool and JDBC resource on GlassFish server to access database server.
g. Restart GlassFish
h. Deploy application WAR
We explain these simple steps below.
Collecting distributable files
Right click on the project in Projects window and in the context menu, click Clean and Build.
Fig. 1: Clean and Build Project
Cleaning process deletes the folders where compiled classes were deposited and Build recreates the folders and deposits again the recompiled results. The project folder structure is in Fig. 2.
Fig. 2: NetBeans project folder structure
The ‘dist’ folder contains a WAR (Web Archive) file. In our case this file is: dataProject.war. This file along with MySQL Java connector file, mysql-connector-java-5.1.5-bin.jar are to be distributed to the site where the Project is to be installed. Also note at this time MySQL connection related information available in sun-resources.xml file under Server Resources (Fig. 3 and Fig. 4).
Fig. 3: Server Resources node in dataProject
Note in Fig. 4, the jndi-name (jdbc/expt_MySQL) and connection pool-name, mysqlPool, and associated connection particulars such as serverName, portNumber etc. We will need them at the site we are going to install the project.
Fig. 4: sun-resources.xml file under Server Resources. Read the first line after <resources> tag
GlassFish configuration
Domain creation
You have installed on a remote Linux machine NetBeans with GlassFish, Java Application Server. Your project is to be installed there. Decide first the user on whose account and home space, the GlassFish domain will be created. Log on as that user. Domain creation is easy with NetBeans. Start NetBeans, and on start the first thing it does is to look for the GlassFish domain. And if it is not there, creates one by name of personalDomain under the folder .personalDomain. Here is what appears under output window.
Please, wait while the domain is being created...
Using port 9237 for Admin.
Using port 12469 for HTTP Instance.
Using port 12065 for JMS.
Using port 8089 for IIOP.
Using port 12570 for HTTP_SSL.
Using port 8209 for IIOP_SSL.
Using port 8309 for IIOP_MUTUALAUTH.
Using port 13075 for JMX_ADMIN.
Domain being created with profile:developer, as specified by variable AS_ADMIN_PROFILE in configuration file.
Security Store uses: JKS
Domain personalDomain created.
Note the port related information. The GlassFish Admin console will be available at port 9237 (http://localhost:9237), the web-site will be available at port 12469 (http://localhost:12469/dataProject) and web-site with SSL protection will be available at port 12570 (https://localhost:12570/dataProject). Do not worry if you did not note down this information at the time personal domain was created. In NetBeans, under Servers node, right-click GlassFish and in the context menu click Properties (Fig. 5) to know the location of Admin console.
Fig. 5: Location of Admin Console at port 9237
You can also get this information by peeping into the log files and looking for lines with words ‘Starting’. Or, from the command line issue command as:
[mohammed@gnu ~]$ cat .personalDomain/personalDomain/logs/server.log | grep Starting
Starting GlassFish Server
When personalDomain is created, two script files are also deposited in its ‘bin’ folder (Fig. 6).
Fig. 6: Folder structure of personalDomain
In the terminal window, change directory to ‘bin’ folder and issue startserv command (Fig. 7). You will need to supply admin username, his password and master password. The master password is used to secure the SSL key-store of the domain. It is not used for authentication.
Fig. 7: Starting GlassFish server. Note the default master password
The server can be stopped by another script in the ‘bin’ folder as:
[mohammed@gnu bin]./stopserv
GlassFish server can also be started from NetBeans. Right click the GlassFish node (Fig. 5) and in the context menu, click Start.
Adding Database Driver
It is time that we add MySQL database driver’s JAR file to enable the server to connect to MySQL server. Copy the file mysql-connector-java-5.x-bin.jar to lib folder (Fig. 6) of personalDomain. This will do.
Creating connection pool for MySQL server
GlassFish application server uses Connection Pooling mechanism to speed-up server response time. Creating a new connection to database server for each client request takes a long time. Connection pooling is a mechanism to have a ready connection available and to assign it to a client as soon as a request is made. When the client releases the connection, it returns to pool to be made available to another client. You can view existing Connection pools in NetBeans by expanding GlassFish node when started.
Note from Fig. 4 that our application expects a connection pool by name (pool-name=) of mysqlPool. To create this connection pool, start GlassFish server and access Admin console. In our case, we will access it as http://localhost:9237. In the Admin console, login as user admin and password adminadmin. Server Admin Console opens (Fig. 8).
Fig. 8: Sun Java System Application Server Admin Console
In the Server Admin Console, in the tree on the left, expand Resources->JDBC nodes to see existing connection pools (Fig. 9).
Fig. 9: GlassFish is started. Presently three default connection pools exist
Under Common Tasks (Fig. 10), click Create New JDBC Connection Pool.
Fig. 10: Creating new jdbc connection pool
Page as in Fig. 11 opens. Fill it up as done here and click Next.
Fig. 11: Creating connection pool
In the Next page there is lot of information. Do not bother with it except the Additional Properties section down below that page (Fig. 12).
Fig. 12: Filling in connection related information
Fill up only relevant fields with usual information and click Finish to create the connection pool. We now have to create a JDBC resource by name of jdbc/expt_MySQL on top of this connection pool. Please note that this resource is known by name of jndi-name in Fig. 4. Presently as you can see in Fig. 9, this JDBC resource is not available.
Fig. 13: Existing JDBC Resources
In Fig. 9, click on the JDBC Resources link to open JDBC Resources page (Fig. 13). Here, click on New button. It takes you to Fig. 14. Fill in the simple details and click OK.
Fig. 14: Creating new JDBC resource
The necessary resource has been created. Restart GlassFish server.
Deploying your application
To deploy our application, copy the project WAR file (that was in dist folder of project, Fig. 2) to autodeploy folder (Fig. 6) of personalDomain. The server will explode and install the file. Access the application as: http://localhost:12469/dataProject/. You can also deploy the application through Admin Console. In Fig. 8, click on Deploy Web Application (WAR) to open page as in Fig. 15.
Fig. 15: Deploying application through Admin Console
Here Browse to your WAR file location and click OK. The WAR file is deployed.
***************