Chapter 5 - Deploying Enterprise Java Web Application to JBoss
Chapter 5 - Deploying Enterprise Java Web Application to JBoss
DB Visual ARCHITECT (DB-VA) provides different kinds of templates for users to generate Java code. The template will optimize the configuration of generated Java Code and select jar files for different application servers or standalone Java application. DB-VA supports to generate configuration file to make the web application use datasource connection to connect to database in the application server. In this chapter, we will deploy enterprise Java web application to JBoss Application Server.
In this chapter:
- Introduction
- Preparing to Deploy to JBoss
- Deploying Web Application to JBoss
- Configuring Datasource on JBoss
- Configuring Datasource Connection on DB-VA
Introduction
This document is based on the Programmer's Guide for Java - Chapter 3 Developing Java Enterprise Web Application example to demonstrate the deployment step on the JBoss Server. The Example of Programmer's Guide for Java - Chapter 3 is deployed on JBoss, so we will point out some of its important steps. Finally, we will configure the web application to use the datasource connection provide by JBoss application server to connect to database.
Preparing to Deploy to JBoss
Suppose you have downloaded the example of the Programmer's Guide for Java - Chapter 3 Developing Java Enterprise Web Application.
- From the menu bar, select Tools > Object Relational Mapping (ORM) > Generate Code... to open the Database Code Generation dialog box.
- Set Deploy To option to JBoss Application Server.
DB-VA helps you to select the corresponding Optional Jar files.
- Click OK to regenerate code.
Copy the schoolsystem.war\src\ormmapping folder to schoolsystem.war\classes folder to make sure the configure files are also updated.
Deploying Web Application to JBoss
- After developed the web application with the generated Java code, you must copy the web application folder (named "XXX.war" , for example "schoolsystem.war" ) and to the JBoss deploy folder (JBOSS_HOME\server\default\deploy). For development of the Web Application, you can refer to the Programmer's Guide for Java - Chapter 3 Developing Java Enterprise Web Application.
- Start the JBoss server. Execute the JBOSS_HOME\bin\run.bat.
- Go to http://localhost:8080/schoolsystem/index.html. You can access the database by JDBC connection
Configuring Datasource on JBoss
The JBoss server can provide a datasource for application to share the JDBC connection within the server. The following steps show you how to configure datasource on JBoss application server. We will configure the MySQL database on JBoss server as an example.
- Copy the JDBC driver to the JBOSS_HOME\server\default\lib
In this example, DB-VA generated persistent libraries include orm.jar and mysql.jar. mysql.jar is the JDBC driver for MySQL database. mysql.jar can be found at schoolsystem.war\WEB-INF\lib.
- Copy mysql-ds.xml from JBOSS_HOME\docs\example\jca to the deploy folder (JBOSS_HOME\server\default\deploy) and modify the content to follow the table below.
| jndi-name |
app/schoolsystem |
| connection-url |
jdbc:mysql://localhost/schoolsystem |
| driver-class |
com.mysql.jdbc.Driver |
The sample of modified mysql-ds.xml:
<?xml version="1.0" encoding="UTF-8"?>
<datasources> <local-tx-datasource> <jndi-name>app/schoolsystem</jndi-name>
<connection-url>jdbc:mysql://localhost/schoolsystem</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name>
<password></password>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
</exception-sorter-class-name>
<metadata> <type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
- The JBoss server creates a datasource and bound it to JNDI name 'java:app/schoolsystem'.
Configuring Datasource Connection in DB-VA
After configuring the datasource on the JBoss server, you can modify the generate Java code configuration to use the datasource connection to connect the database within JBoss server.
- From the menu bar, select Tools > Object Relational Mapping (ORM) > Generate Code ... to open the Database Code Generation dialog box.
- Select the Database tab and select the Connection option from JDBC to Datasource.
- Enter the following information to configure the datasource on JBoss Server.
| Dialect |
org.hibernate.dialect.MySQLInnoDBDialect |
| Datasource JNDI Name |
java:app/schoolsystem |
| JNDI Provider URL |
localhost:1099 |
| JNDI InitialContextFactory class |
org.jnp.interfaces.NamingContextFactory |
| User name |
root |
| Password |
(empty) |
| TransactionManagerLookup class |
org.hibernate.transaction.JBossTransactionManagerLookup |
| TransactionFactory class |
org.hibernate.transaction.JTATransactionFactory |
Table 5.1
Click OK to regenerate the code.
- Copy the new configuration files from schoolsystem.war\src\ormmapping folder to schoolsystem.war\classes folder and use the jar command to create a new war file.
- Copy the web application folder to the JBoss deploy folder again, then it will redeploy and use the datasource to connect to the database.
|
|
| Visual Paradigm International Limited |
| Website: |
www.visual-paradigm.com |
| E-mail: |
support@visual-paradigm.com |
|