1 Reply Latest reply on Dec 19, 2002 3:07 AM by Mark

    Building and running PetStore1.1.2 using JBoss3.0.0 and MySq

    altrine christopher Newbie

      Hello JBoss users,
      After several days of arduous effort searching for different types of error details and stack trace related to JPS1.1.2, I was able to compile and deploy the same(java blueprints java petstore application version 1.1.2) onto JBoss3.0.0. Presented here are the detailed steps that I documented during the course of deploying the petstore application.

      The documentation which I read from sites and JBoss3.0.0 quick-reference pdfs provided a birds-eye view and lack a tutorial kind of approach. This made me to give-up using JBoss as my application server, however, If you re-read those pdfs, you will get some hints which will be helpful in getting things done!.
      I read JBoss 2.2+ Documentation to setup up JBoss3.0.0 but later on, I found the correct document that I was looking for i.e. JBoss3.0 documentation. I have provided the links below.
      JBoss2.2+ Doc - http://star.cs.byu.edu/JBossDocs/html/fancy/
      JBoss3.0 - http://klomdark.servebeer.com:8081/docs/jboss-docs/
      MySql-JBoss service setup - http://www.csd.abdn.ac.uk/~bscharla/teaching/mtp_software/mysql/index.shtml

      Ok, before I begin, here is my environment.
      1. Operating System - Microsoft Windows XP - Home Edition.
      2. Java = Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_04-b02) or JDK 1.3.1
      3. Application Server - JBoss-3.0.0_tomcat-4.0.3
      4. Java Petstore1.1.2
      5. Ant = One that came with the petstore1.1.2.
      6. Database = MySQL 3.23.51
      Step 1: Download and install JDK 1.3.1 or above (Warning!!! chances are there to get some errors or exceptions) and petstore1.1.2
      This step is easy. Install JDK and Set the environment variable JAVA_HOME
      Unzip java petstore1.1.2 to a dir and set the JPS_HOME
      ex. JAVA_HOME=c:\jdk1.3.1
      JPS_HOME=c:\jps1.1.2

      Step 2: Download and install JBoss-3.0.0_tomcat-4.0.3 or latest version (again warning!!, may throw exceptions).
      This step is also easy, just download and unzip the JBoss-3.0.0_tomcat-4.0.3 server. The easy way is to download the binaries.
      2a. Set the environment variable JBOSS_HOME, PATH, CLASSPATH
      ex.
      JBOSS_HOME=C:\jboss-3.0.0_tomcat-4.0.3
      J2EE_HOME=C:\jboss-3.0.0_tomcat-4.0.3
      PATH=%JAVA_HOME%\bin;

      My CLASSPATH variable includes the following.
      Set CLASSPATH=%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\tools.jar;%JBOSS_HOME%\catalina\common\lib\servlet.jar;%JBOSS_HOME%\client\jboss-j2ee.jar;%JBOSS_HOME%\client\jboss-client.jar;%JBOSS_HOME%\client\jbosssx-client.jar;%JBOSS_HOME%\client\log4j.jar;%JBOSS_HOME%\client\jnp-client.jar;%JBOSS_HOME%\client\jnet.jar;%JBOSS_HOME%\client\jboss-common-client.jar;.;%CLASSPATH%
      2b.

      Note: Before you start the following section, try to build the petstore application as it is without making any change. Once you are able to see the successful generation of .ear file, then go ahead and follow the steps.

      The source code is located in the $JPS_HOME/src/petstore/src/ (UNIX) or %JPS_HOME%\src\petstore\src\ (Win32).
      Navigate through the source directory and do as given below.
      Add the respective jboss.xml to each of the component's src dirs except util.
      e.g. To the customer component, I added jboss.xml file under C:\jps1.1.2\src\components\customer\src.
      For more information about jboss.xml file read the documentation. Similarly add jboss.xml for other components also. The description of each and every jboss.xml file is given below.

      During build process, we need to add jboss.xml under the META-INF dir, so copy it to that dir. This is done by making a change in the build file as follows.

      Changes made to the file C:\jps1.1.2\src\components\customer\src\build.xml
      Changed ${j2ee.home}/lib/j2ee.jar to ${jboss.home}/client/jboss-j2ee.jar
      Added
      *******************begin jboss.xml for customer component**************
      <?xml version="1.0" encoding="ISO-8859-1"?>

      <enterprise-beans>

      <ejb-name>TheAccount</ejb-name>
      <resource-ref>
      <res-ref-name>jdbc/EstoreDataSource</res-ref-name>
      <jndi-name>java:/EstoreDB</jndi-name>
      </resource-ref>


      <ejb-name>TheOrder</ejb-name>
      <resource-ref>
      <res-ref-name>jdbc/EstoreDataSource</res-ref-name>
      <jndi-name>java:/EstoreDB</jndi-name>
      </resource-ref>

      </enterprise-beans>
      <resource-managers>
      <resource-manager res-class="org.jboss.ejb.deployment.JDBCResource">
      <res-name>jdbc/EstoreDataSource</res-name>
      <res-jndi-name>java:/EstoreDB</res-jndi-name>
      </resource-manager>
      </resource-managers>

      *****************end jboss.xml for customer component***********************

      Changes made to the file C:\jps1.1.2\src\components\inventory\src\build.xml
      Changed ${j2ee.home}/lib/j2ee.jar to ${jboss.home}/client/jboss-j2ee.jar
      Added
      *****************begin jboss.xml for Inventory component*********************

      <enterprise-beans>

      <ejb-name>TheInventory</ejb-name>
      <resource-ref>
      <res-ref-name>jdbc/InventoryDataSource</res-ref-name>
      <jndi-name>java:/InventoryDB</jndi-name>
      </resource-ref>

      </enterprise-beans>
      <resource-managers>
      <resource-manager res-class="org.jboss.ejb.deployment.JDBCResource">
      <res-name>jdbc/InventoryDataSource</res-name>
      <res-jndi-name>java:/InventoryDB</res-jndi-name>
      </resource-manager>
      </resource-managers>

      *****************end jboss.xml for Inventory component***********************

      Changes made to the file C:\jps1.1.2\src\components\mail\src\build.xml
      Changed ${j2ee.home}/lib/j2ee.jar to ${jboss.home}/client/jboss-j2ee.jar
      Added
      *****************begin jboss.xml for mail component**************************

      <enterprise-beans>

      <ejb-name>TheMailer</ejb-name>
      <resource-ref>
      <res-ref-name>mail/MailSession</res-ref-name>
      <jndi-name>java:/MailSession</jndi-name>
      </resource-ref>

      </enterprise-beans>
      <resource-manager res-class="">
      <res-name>mail/MailSession</res-name>
      <res-jndi-name>java:/MailSession</res-jndi-name>
      </resource-manager>

      *****************end jboss.xml for mail component***************************

      Changes made to the file C:\jps1.1.2\src\components\personalization\src\build.xml
      Changed ${j2ee.home}/lib/j2ee.jar to ${jboss.home}/client/jboss-j2ee.jar
      Added

      *****************begin jboss.xml for personalization component******************

      <enterprise-beans>

      <ejb-name>TheProfileMgr</ejb-name>
      <resource-ref>
      <res-ref-name>jdbc/EstoreDataSource</res-ref-name>
      <jndi-name>java:/EstoreDB</jndi-name>
      </resource-ref>

      </enterprise-beans>
      <resource-managers>
      <resource-manager res-class="org.jboss.ejb.deployment.JDBCResource">
      <res-name>jdbc/EstoreDataSource</res-name>
      <res-jndi-name>java:/EstoreDB</res-jndi-name>
      </resource-manager>
      </resource-managers>

      *****************end jboss.xml for personalization component*******************

      Changes made to the file C:\jps1.1.2\src\components\shoppingcart\src\build.xml
      Changed ${j2ee.home}/lib/j2ee.jar to ${jboss.home}/client/jboss-j2ee.jar
      Added
      *****************begin jboss.xml for shoppingcart component********************

      <enterprise-beans>

      <ejb-name>TheCatalog</ejb-name>
      <resource-ref>
      <res-ref-name>jdbc/EstoreDataSource</res-ref-name>
      <jndi-name>java:/EstoreDB</jndi-name>
      </resource-ref>

      </enterprise-beans>
      <resource-managers>
      <resource-manager res-class="org.jboss.ejb.deployment.JDBCResource">
      <res-name>jdbc/EstoreDataSource</res-name>
      <res-jndi-name>java:/EstoreDB</res-jndi-name>
      </resource-manager>
      </resource-managers>

      *****************end jboss.xml for shoppingcart component*********************

      Changes made to the file C:\jps1.1.2\src\components\signon\src\build.xml
      Changed ${j2ee.home}/lib/j2ee.jar to ${jboss.home}/client/jboss-j2ee.jar
      Added

      *****************begin jboss.xml for signon component************************

      <enterprise-beans>

      <ejb-name>TheSignOn</ejb-name>
      <resource-ref>
      <res-ref-name>jdbc/SignOnDataSource</res-ref-name>
      <jndi-name>java:/EstoreDB</jndi-name>
      </resource-ref>

      </enterprise-beans>
      <resource-managers>
      <resource-manager res-class="org.jboss.ejb.deployment.JDBCResource">
      <res-name>jdbc/SignOnDataSource</res-name>
      <res-jndi-name>java:/EstoreDB</res-jndi-name>
      </resource-manager>
      </resource-managers>

      *****************end jboss.xml for signon component**************************

      Changes made to the file C:\jps1.1.2\src\components\util\tracer\src\build.xml
      Changed ${j2ee.home}/lib/j2ee.jar to ${jboss.home}/client/jboss-j2ee.jar

      Changes made to the file C:\jps1.1.2\src\miniapps\mailerapp\src\build.xml
      Changed ${j2ee.home}/lib/j2ee.jar to ${jboss.home}/client/jboss-j2ee.jar

      In addition to the above changes, modify or replace the application.xml file found at
      C:\jps1.1.2\src\petstore\src\application.xml to have,

      *****************begin application.xml*************************************
      <?xml version="1.0" encoding="UTF-8"?>

      <display-name>PetStore1.1.2 application on JBoss3.0 with MySql Database</display-name>


      shoppingcartEjb.jar


      signonEjb.jar


      inventoryEjb.jar


      personalizationEjb.jar


      mailerEjb.jar


      customerEjb.jar


      petstoreEjb.jar



      <web-uri>petstore.war</web-uri>
      <context-root>estore</context-root>



      <security-role>
      the gold customer role
      <role-name>gold_customer</role-name>
      </security-role>
      <security-role>
      the customer role
      <role-name>customer</role-name>
      </security-role>
      <security-role>
      <role-name>administrator</role-name>
      </security-role>


      *****************end application.xml **************************************

      Also add jboss-web.xml to the dir C:\jps1.1.2\src\petstore\src\docroot\WEB-INF\
      *****************begin jboss-web.xml *************************************
      <?xml version="1.0" encoding="ISO-8859-1"?>

      <jboss-web>
      <resource-ref>
      <res-ref-name>jdbc/EstoreDataSource</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <jndi-name>java:/EstoreDB</jndi-name>
      </resource-ref>
      <ejb-ref>
      <ejb-ref-name>ejb/catalog/Catalog</ejb-ref-name>
      <jndi-name>TheCatalog</jndi-name>
      </ejb-ref>
      <ejb-ref>
      <ejb-ref-name>ejb/cart/Cart</ejb-ref-name>
      <jndi-name>TheCart</jndi-name>
      </ejb-ref>
      <ejb-ref>
      <ejb-ref-name>ejb/customer/Customer</ejb-ref-name>
      <jndi-name>TheCustomer</jndi-name>
      </ejb-ref>
      <ejb-ref>
      <ejb-ref-name>ejb/profilemgr/ProfileMgr</ejb-ref-name>
      <jndi-name>TheProfileMgr</jndi-name>
      </ejb-ref>
      <ejb-ref>
      <ejb-ref-name>ejb/scc/Scc</ejb-ref-name>
      <jndi-name>TheShoppingClientController</jndi-name>
      </ejb-ref>
      <ejb-ref>
      <ejb-ref-name>ejb/inventory/Inventory</ejb-ref-name>
      <jndi-name>TheInventory</jndi-name>
      </ejb-ref>
      </jboss-web>
      *****************end application.xml **************************************
      2c. Replace the line in C:\jps1.1.2\src\components\customer\src\customer_ejb.xml.
      <env-entry-value>com.sun.j2ee.blueprints.customer.order.dao.OrderDAOCS</env-entry-value>
      with
      <env-entry-value>com.sun.j2ee.blueprints.customer.order.dao.OrderDAOMySql</env-entry-value>
      Since we are using MySql we need to create a MySql DAO class. For that copy or do a saveas
      C:\jps1.1.2\src\components\customer\src\com\sun\j2ee\blueprints\customer\order\dao\OrderDAOOracle.java to
      C:\jps1.1.2\src\components\customer\src\com\sun\j2ee\blueprints\customer\order\dao\OrderDAOMySql.java and make the following change.
      Replace---
      < + "ordernum.nextval" + ","
      < + "'" + details.getUserId().trim() + "',"
      < + "to_date('" + details.getOrderDate().getFullDateString()
      < + "','mm/dd/yyyy')" + ","
      < + "'"+details.getShipToAddr().getStreetName1().trim() +"',";
      With---
      > + "NULL" + ","
      > + "'" + details.getUserId().trim() + "',"
      > + "'" + details.getOrderDate().getCloudscapeDateString () + "',"
      > + "'" + details.getShipToAddr().getStreetName1().trim() +"',";
      Replace---
      < queryStr = "SELECT ordernum.currval from " + DatabaseNames.ORDER_TABLE;
      With---
      > queryStr = "SELECT distinct last_insert_id() from " + DatabaseNames.ORDER_TABLE;
      Replace---
      < + "linenum.nextval" + ","
      < + " SYSDATE,"
      With---
      > + "NULL" + ","
      > + " SYSDATE(),"
      Replace---
      < + "orderdate = to_date ('" + ordr.getOrderDate().getFullDateString()
      < + "','mm/dd/yyyy'),"
      With---
      > + "orderdate = '" + ordr.getOrderDate().getCloudscapeDateString () + "',"
      We just have only one more setup, i.e. the database.
      Step 3: Download and install MySQL 3.23.51, drivers matching your environment.
      3a. I assume that you are able to successfully download and setup MySQL DB and have played with it several times.
      3b. create a Database named petstore.
      ex. create database petstore.
      3c. create a user name of your choice granting him all permissions. I created a user named "altrine" and password "cavalier".
      ex. grant all on petstore.* to altrine identified by 'cavalier' ;
      where
      Database = petstore
      username = altrine
      password = cavalier
      3d. Setup the tables and the data that are used by the petstore application. For this, you need to modify the .sql file found under
      C:\jps1.1.2\src\petstore\src\docroot\WEB-INF\sql\ to suit the MySQL table definition.
      Since the syntax of MySql is almost similar to Oracle, copy Oracle.sql to MySql.sql and do the following changes.
      For simplicity, I am going to give modification you need to make to MySql.sql file instead of copying the whole file.
      *****************do the modifications to MySql.sql***************************
      -- add the following line
      use petstore;
      -- remove the following lines
      drop sequence linenum;
      drop sequence ordernum;
      -- find and replace “orderid int not null” by
      orderid int not null AUTO_INCREMENT,
      -- find and replace “linenum int not null” by
      linenum int not null AUTO_INCREMENT,
      -- find and replace “number” by “float”
      -- remove the following 2 lines.
      create sequence ordernum increment by 1;
      create sequence linenum increment by 1;
      -- find and replace public by username ex. altrine
      -- after modification all you grant statements will be similar to the one below except table
      -- name will be different
      grant all on supplier to altrine;
      *****************End MySql.sql ******************************************

      Pipe the above file to MySql client and create the populate the petstore database.
      Ex. mysql>mysql < <MySql.sql file-location>
      Done, the petstore database is now ready.

      I think we are all set now.
      • Change the current directory to %JPS_HOME%\src\petstore\src\ and run build.bat. If the compilation succeeds, petstore.ear will be created in the directory %JPS_HOME%\src\petstore\build\.
      • I am sure there will be errors popping out, modify your files accordingly and re-run build.
      • When deploying the built application, use the file petstore.ear created by the build (as opposed to pre-built one located in the root directory of the J2EE BluePrints bundle).
      • Now copy the petstore.ear file to the deploy dir of JBoss3.0.0 server which is
      • %JBOSS_HOME%\server\default\deploy
      • Make sure MySql database is up and running.
      • Start the JBoss server %JBOSS_HOME%\bin\run.bat
      • Click the url : http://localhost:8080/estore/

      You will encounter the following message as given in this forum message.
      http://www.jboss.org/modules/bb/index.html?module=bb&op=viewtopic&t=forums/ the instruction from this forum message to get it work successfully.

      All the best folks,
      altrine.