Java Pet Store Tutorial

 
 
The Java Pet Store is a popular J2EE example application in the J2EE Blueprints series, created by Sun Microsystems. It models an e-commerce application where customers can purchase pets online using a Web browser. The purpose of this application is to demonstrate the capabilities of the J2EE platform and is written for learning purposes (for example to illustrate the many different design patterns on various part of J2EE). It is not coded for performance and is not intended for performance benchmarks.

The Java Pet Store 1.3.2 follows the J2EE 1.3 specs which is a set of related specifications and can be seen as a single standard for implementing and deploying enterprise applications. Java Pet Store 1.3.2 demonstrates the following:
  • How to use Java Server Pages (jsp).
  • How to use Java Servlets.
  • How to use Enterprise JavaBeans (EJB).
  • How to use Java Message Service (JMS).
  • How to use JSP Standard Tag Library (JSTL).
  • How to use the Java API for XML-based RPC (JAX-RPC).
  • How to use SOAP.
  • How to exchange and process XML-based documents.
  • How to develop flexible, scalable, cross-plaform enterprise applications.
  • How to use the Java BluePrints guidelines and patterns.
  • Illustrate basic usage of J2EE technology with current best practices.
The Pet Store application comes with full source code and documentation, and the latest release can be downloaded from: http://java.sun.com/blueprints/code/index.html#java_pet_store_demo

More information about Pet Store can be found at:
http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/
sample-app/sample-app1.3.1a3.html


ATTENTION:
The petstore-1_3_2.zip is no longer available at the http://java.sun.com/blueprints/ site.
Sun.com discourage people from investing time in learning it since its old, and instead encourage developers to learn the newer material.

However there are several companies using the old BluePrints Web Application Framework (WAF) where the petstore 1.3.2 demo is based on. Download the petstore-1_3_2.zip file.








Pet Store 1.3.2 implemented on Jboss 3.2.3 and MySQL 4.0.18



Information
none

Operating system used
Windows XP Home Edition Version 5.1 SP 2

Software prerequisites
Ant 1.6.1
J2SE 1.4.2
J2EE 1.3.1
JBoss 3.2.3
MySQL 4.0.x
MySQL Connector/J 3.0.11
Java Pet Store 1.3.2

Procedure
  1. Make sure JBoss 3.2.3 is installed and it is working with MySQL 4.0.x. See above mentioned software prerequisites. Pet Store 1.3.2 does not need to be set up, just download and unzip it.

    After this has been done it is highly recommended to backup the following files as this procedure will overwrite these files:

    • ${JBOSS_DEFAULT_CONF}/deploy/mysql-ds.xml
    • ${JBOSS_DEFAULT_CONF}/deploy/jms/jbossmq-destinations-service.xml
    • ${PETSTORE_HOME}/src/apps/petstore/src/docroot/
      CatalogDAOSQL.xml
    • ${PETSTORE_HOME}/src/apps/petstore/src/docroot/
      populate/PopulateSQL.xml
    • ${PETSTORE_HOME}/src/apps/petstore/src/docroot/
      WEB-INF/web.xml
    • ${PETSTORE_HOME}/src/components/catalog/src/ejb-jar.xml

  2. Download and unzip jboss_petstore_patch.jar. This unzipped directory will be referred as ${PATCH_HOME}.

  3. Edit Ant properties file ${PATCH_HOME}/buildscript/build.properties
    Change the settings according to your situation:
    PATCH_HOME=C:/jboss_petstore_patch
    PETSTORE_HOME=C:/Tools/petstore1.3.2
    JBOSS_DEFAULT_CONF=C:/Tools/jboss-3.2.3/server/default

  4. Edit file ${PATCH_HOME}/buildscript/build.bat
    Change the settings according to your situation:
    set JAVA_HOME=C:/Tools/java/j2sdk1.4.2_01
    set J2EE_HOME=C:/Tools/java/j2sdkee1.3.1
    set ANT_HOME=C:/Tools/apache-ant-1.6.1



  5. The script ${PATCH_HOME}/buildscript/database.sql creates a database called petstore. If this database name is already in use change the database name in something else in the following files:

    • File: ${PATCH_HOME}/buildscript/database.sql

      DROP DATABASE IF EXISTS your_database_name;
      CREATE DATABASE your_database_name;


    • File: ${PATCH_HOME}/jboss_3.2.3/config/mysql-ds.xml

      ..jdbc:mysql://localhost:3306/your_database_name?useUnicode=..

  6. Start MySQL:
    Open a dos window and type: net start mysql

  7. Copy ${PATCH_HOME}/buildscript/database.sql to C:\..\mysql\bin

  8. Setup MySQL database, execute database.sql script:
    e.g.: C:\..\mysql\bin>mysql -uUSERNAME -pPASSWORD < database.sql

    For example:
    C:\..\mysql\bin>mysql -uroot -pmysecret < database.sql

  9. The Ant ${PATCH_HOME}/buildscript/build.xml file contains the following tasks:

    Command Description
    build preparejboss Copy xml configuration files to Jboss environment.
    build build Creates petstore.ear, petstoreadmin.ear, opc.ear and supplier.ear for JBoss.

    The four ear files can be found in:
    ../tmp_dist
    build deploy Deploys the four ear files to JBoss default deploy directory.
    build undeploy Removes the four ear files from the JBoss default deploy directory.
    build all Default setting:
    build and deploy tasks are executed.

    View Pet Store 1.3.2 build process.


    It is now time to create the petstore.ear, petstoreadmin.ear, opc.ear and supplier.ear files for Jboss 3.2.3:

    • cd ${PATCH_HOME}/buildscript/
    • Type: build preparejboss
    • Type: build all

    The four ear files can be found at ${PATCH_HOME}/tmp_dist and are deployed at ${JBOSS_DEFAULT_CONF}/deploy.

  10. Start JBoss:
    e.g.: C:\Tools\jboss-3.2.3\bin\run.bat

  11. During Jboss startup, no error messages shoud be displayed.
    View JBoss messages during the startup.

  12. To verify if all is working:
    http://localhost:8080/petstore
    http://localhost:8080/admin
    http://localhost:8080/supplier

  13. If you are not interested in building the Jboss Pet Store ear files or you are not able to build these files, you can download them here:


    If you use these ear files do not forget to:
    • Run ${PATCH_HOME}/buildscript/database.sql
    • Execute Ant task: build preparejboss