WebSphere EJB 2
NOTE: These instructions only apply if you want to use EJB2 (with CMP); if you use Hibernate or EJB3 JPA you can deploy the war from OpenXava directly in the WebSphere. It's not advisable to use EJB2 for new developments.
OpenXava generates J2EE aplications deployables in
IBM Websphere Application Server 5.0, 5.1, 6.0 y 6.1.
Doing this simply requires executing a ant target that generates an EAR compatible with Websphere. Touching your code or XML files is not necessary.
This allows you developing your application using JBoss (hence in an agile way) and when it is ready for production deploy it in Websphere and of course test it.
This document is a guide for deploying an OpenXava application in Websphere. If you does not have one yet it's better that before this guide follow the tutorial of OpenXava, and you will obtain a MySchool.ear.
The next instructions work with Websphere 5.0, 5.1 and 6.0. In the examples you will connect to an AS/400, but is very easy using another database instead.
Create a J2EE Websphere compatible application
Open your Eclipse and make that it point to the
workspace that comes with OpenXava distribution.
- Edit MySchool/build.xml and set the variable configuration to websphere-as400.
- Regenerate code, with the ant target MySchool.regenerateEJB.
- Compile, click on Build.
- Execute the target ant MySchool.createWebsphereEar.
And now you have in MySchool.dist a file named MySchool.ear ready to deploy in Websphere.
Install Websphere
This step is your own business. Use the IBM instructions about this topic and have luck. Install the last patch level too.
Setup Data Sources
Open the admin console, going to
http://localhost:9090/admin (or
http://localhost:9060/admin in version 6)
First you have to create a J2C entry, that contains an alias for an user/password that you will use in order to authenticate against your database.
- In version 5/5.1: Go to Security >JAAS Configuration > J2C Authentication Data.
- In version 6: Go to Security > Global Security > JAAS Configuration (on right) > J2C Authentication Data
- Click New.
- In Alias fielD type openxava (or another one of your choice).
- In User ID field type the name of a database user.
- In Password field type the password of that user.
- Click OK.
- Click Save that goes to another page and click in Save button.
Register your JDBC driver:
- Go to Resources > JDBC Providers.
- Click New.
- In version 5/5.1:
- In JDBC Providers field choose DB2 UDB for iSeries (Toolbox XA), or the driver for your database, always the XA version.
- Click Apply.
- In Classpath field type the path for your JDBC Driver (including jar name).
- Click Apply.
- In version 6:
- Step 1: Choose DB2 (or your database type).
- Step 2: DB2 UDB for iSeries (Toolbox) (or your provider type).
- Step 3: XA data source (always this).
- Click Next.
- In Classpath field type the path for your JDBC Driver (including jar name).
- Click Apply.
Register the Data Source for OpenXava:
- Click in Data Sources (it's on bottom in 5/5.1, it's on right in 6).
- Click New.
- In Name field type OpenXavaDS
- In JNDI Name field type jdbc/OpenXavaDS
- In Component-managed Authentication Alias field choose xxxx/openxava.
- In Container-managed Authentication Alias choose xxxx/openxava.
- In version 5/5.1:
- Click Apply.
- Click Custom Properties, this goes to another page.
- Click serverName and in Value field type the IP of your AS/400 (this only for AS/400).
- Click OK.
- In version 6:
- In serverName field type the IP of your AS/400 (this only for AS/400).
- Click OK.
Registre the Data Source for your application:
- Go to Data Sources.
- Click New.
- In Name field type MySchoolDS
- In JNDI Name field type jdbc/MySchoolDS
- Check the checkbox Container managed persistence.
- In Component-managed Authentication Alias field choose xxxx/openxava.
- In Container-managed Authentication Alias choose xxxx/openxava.
- In version 5/5.1:
- Click Apply.
- Click Custom Properties, this goes to another page.
- Click serverName and in Value fiel type the IP of your AS/400 (this only for AS/400).
- Click OK.
- In version 6:
- In serverName field type the IP of your AS/400 (this only for AS/400).
- Click OK.
- Click Save that goes to another page and click in Save button.
Verify the Data Sources just defined:
- Go to Resources > JDBC Providers.
- Click DB2 UDB for iSeries.
- Click Data Sources (It's on bottom).
- Choose the two data sources just created by you.
- Click on Test Connection button.
If message is satisfactory you have concluded well this step.
Create tables in database
Execute the next script against your DB:
CREATE COLLECTION OPENXAVA;
CREATE TABLE OPENXAVA.TABUSERPREFERENCES
(OID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 0) NOT NULL PRIMARY KEY,
USER VARCHAR(20),
TAB VARCHAR(100),
PROPERTIESNAMES VARCHAR(512));
CREATE INDEX OPENXAVA.TABUSERPREFERENCES01
ON OPENXAVA.TABUSERPREFERENCES(USER,TAB);
CREATE COLLECTION MYSCHOOL;
CREATE TABLE MYSCHOOL.TEACHER(ID VARCHAR(5) NOT NULL PRIMARY KEY,NAME VARCHAR(40));
CREATE TABLE MYSCHOOL.PUPIL(NUMBER INTEGER NOT NULL PRIMARY KEY,NAME VARCHAR(40),TEACHER VARCHAR(5));
INSERT INTO MYSCHOOL.TEACHER VALUES('JP','FRANCISCO JAVIER PANIZA LUCAS');
INSERT INTO MYSCHOOL.TEACHER VALUES('MC','M. CARMEN GIMENO ALABAU');
INSERT INTO MYSCHOOL.PUPIL VALUES(1,'LARS',NULL);
INSERT INTO MYSCHOOL.PUPIL VALUES(2,'ANA','JP');
INSERT INTO MYSCHOOL.PUPIL VALUES(3,'LUIS MIGUEL','JP');
INSERT INTO MYSCHOOL.PUPIL VALUES(4,'MIGUEL',NULL);
Install application
In order to install your application you have to do:
- Go to Applications > Enterprise Applications.
- Click Install.
- Click Examine in Local path field, and choose your application ear.
- Click Next.
- Click Next.
- Click Continue.
- Step 1: Click Next.
- In version 5/5.1:
- Step 2: Choose DB2UDBISERIES or the appropriate for you database and click Next.
- In version 6:
- Step 2: Click Next.
- Step 3: Choose DB2UDBISERIES or the appropriate for you database and click Next.
- Step 6: A warning is shown. Press Continue.
- Step 8: A warning is shown. Press Continue.
- In the others steps click Next, until Finish appears, click it too.
- Be patient, your application is now deploying...
- Click Manage applications.
- Click on MySchool.
- In WAR Classloader Policy choose Application.
- Click Apply.
- Click Web Modules (it's on bottom).
- Click MySchool.war.
- In Classloader Mode field choose PARENT_LAST.
- Click OK.
- Click Save that goes to another page and click in Save button.
Execute the application
Now everything is ready to execute you application in Websphere:
Also you can execute your JUnit Test, in your Eclipse:
- Editt MySchool/properties/xava-junit.properties.
- Change port=8080 by port=9080.
- Execute TeachersTest as a JUnit Test.