Chapter 3 - Deploying Enterprise Java Web Application to IBM WebSphere
Chapter 3 - Deploying Enterprise Java Web Application to IBM WebSphere
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. In this chapter, we will deploy enterprise Java web application to IBM WebSphere. If the application server supports datasource, you can also configure DB-VA to use datasource connection to connect the database on the server.
In this chapter:
- Introduction
- Preparing to Deploy to WebSphere
- Deploying Web Application to WebSphere
- Configuring Datasource on WebSphere
- 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 WebSphere Server. The Example of Programmer's Guide for java - Chapter 3 is deployed on the JBoss Server, we need to modify some configuration before deploy on the WebSphere Server. Finally, we will configure the web application to use the datasource connection provide by WebSphere server to connect to database.
Preparing to Deploy to WebSphere
Suppose you have downloaded the example of the Programmer's Guide for Java - Chapter 3 Developing Java Enterprise Web Application. You need to change the template of generated code before deploy on the WebSphere Server.
- From the menu bar, select Tools > Object Relational Mapping (ORM) > Generate Code ... to open Database Code Generation dialog box.
- Change Deploy To option from JBoss Application Server to Generic Application Server.
DB-VA helps you to select the corresponding Optional Jar files and set datasource options.
- Click OK to regenerate code.
Copy the schoolsystem.war\src\ormmapping folder to schoolsystem.war\classes folder to make sure the configuration files are also updated.
Deploying Web Application to WebSphere
Now the orm.jar is updated and generated in the JBoss Server deploy folder.
- Open the command prompt to the schoolsystem.war folder in the JBoss deploy folder.
- Execute jar to create a war file in command prompt.
The command to create a war file:
jar - cvf schoolsystem.war .
The schoolsystem.war file is created inside the schoolsystem.war folder
- Startup WebSphere Application Server 6. Start menu > All Program > IBM WebSphere > Application Server v6 > Profiles > AppSrv01 > Start the server.
- Go to Administration Console (http://localhost:9061/ibm/console) to login (note that the port number for some WebSphere users may not be 9061, so replace it with the correct one in such case).
- Select Applications > Install New Application to install the schoolsystem.war file
- Select the War file and fill in the Context Root (schoolsystem)
- Click Next to finish the installation.
- Click Save to Master Configuration and click Save in this page to apply all changes.
- Start the new deploy SchoolProject Web Application. Select Applications > Enterprise Application.
- Select schoolsystem_war and click the Start button to startup the Web Application on the server.
- Go to (http://localhost:9081/schoolsystem/index.html) to confirm the web application is running
Configuring Datasource on WebSphere
The WebSphere server can provide a datasource for application to share the JDBC connection within the server. The following steps teach you how to configure datasource on WebSphere server. We will configure the MySQL datasource on WebSphere server as an example.
- Go to Administration Console (http://localhost:9061/ibm/console ) to login.
- Select Resources > JDBC Providers
- Click New button to create MySQL JDBC provider
- In Choose a type of JDBC provider, set all options to User-defined
- Fill in general properties and click Apply.
| Name |
MySQL JDBC provider |
| Classpath |
C:\DevelopApps\jboss-4.0.3SP1\server\default\deploy\schoolsystem.war\WEB-INF\lib\mysql.jar |
| Implementation class name |
com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource |
- Select the Additional Properties > Data sources on the right hand side.
- Click the New button to create new MySQL Data source.
- Fill in new MySQL Data source information and click Apply
| Name |
MySQL Datasource |
| JNDI name |
app/schoolsystem |
| Data store helper class name |
Select a data store helper class |
- Select the Additional Properties > Custom properties on the right hand side.
- Click the New button to create the new property
- Add url property and click OK to create the url property
| Name |
url |
| Value |
jdbc:mysql://localhost/schoolsystem |
- Click Save to apply all previous JDBC and datasource setting
- Select the J2EE Connector Architecture (J2C) authentication data entries. It can create the data entries of username and password to connect to database.
- Click New to create the user IDs and password.
- Enter the Alias, User ID and Password and click Apply to save and return to the MySQL Datasource Page.
- Select the previously created username and password on Container-managed authentication and then click Apply.
- Select the MySQL Datasource to Test connection
- The test connection is successful
Configuring the Datasource on DB-VA
You have setup the datasource on the WebSphere and JNDI name called "app/schoolsystem" . You can configure the datasource connection to make the web application to use the datasource on the 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 WebSphere Server
| Dialect |
org.hibernate.dialect.MySQLInnoDBDialect |
| Datasource JNDI Name |
app/schoolsystem |
| JNDI Provider URL |
(empty) |
| JNDI InitialContextFactory class |
com.ibm.websphere.naming.WsnInitialContextFactory |
| User name |
(connect database user name) |
| Password |
(connect database password) |
| TransactionManagerLookup class |
org.hibernate.transaction.WebSphereExtendedJTATransactionLookup |
| TransactionFactory class |
org.hibernate.transaction.JTATransactionFactory |
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.
- Uninstall the schoolsystem application on WebSphere Application server.
- Repeat the Deploying to WebSphere steps to redeploy the application. The web application can then use the datasource on the server to connect to database.
|
|
| Visual Paradigm International Limited |
| Website: |
www.visual-paradigm.com |
| E-mail: |
support@visual-paradigm.com |
|