Install the application

Presentation

The Java EE 5 book enables you to develop an e-commerce application using multiple Java EE 5 specifications. Throughout the chapters you have to develop layer after layer (persistence, session facade, web interface, electronic shopping cart, web services and asynchronous processing) to obtain a web site to sale domestic animals.

Download the code

First of all, you have to download the code of the application.

Directories structure

Uncompress the file that you have just downloaded and you will obtain three principal sub-directories. Those correspond to the various applications:

  • the e-commerce site itself (Yaps Pet Store) is in the yaps directory
  • the BarkBank web service to validate credit cards in the barkbank directory
  • the PetEx web service Web in the petex directory

As you can see it in the images below, each one of these applications is made up of sub-directories.

Each sub-directory contains specific files:

  • build: contains the files to be deployed in GlassFish (war and ear)
  • classes: directory containing the bytecode of the application
  • config: contains the files to configure the application
  • generated: Java classes generated for the web services
  • resources: Web pages and images of the web site
  • src: this directory contains the Java source files of the application
  • WEB-INF: contains the files to configure the web application

Install the tools

Before running the application, make sure that you have the needed tools installed:

  • JDK
    • Install a version of the JDK equal or higher than 1.5_11
    • Set the JAVA_HOME variable
  • Ant
    • Install a version of Ant equal or higher than 1.7
    • Set the ANT_HOME variable
    • Add the %ANT_HOME%/bin directory in your PATH
  • GlassFish
    • Install a version of Glassfish equal or higher than V2b41
    • Download the jar file and then run the commande java -Xmx256m -jar fileName.jar
    • Set the GLASSFISH_HOME variable
    • Enter the command %GLASSFISH_HOME%/ant -f setup.xml to end the GlassFish setup
    • Add the %GLASSFISH_HOME%/bin directory in your PATH

Set up the servers

Now you have to setup GlassFish and the database. Ant admin tasks are in the %PETSTORE_HOME%/admin.xmlfile

  • Create the petstore domain in GlassFish using the following passwords (admin port is 8282)
%GLASSFISH_HOME%/\bin/\asadmin create-domain --adminport 8282 --user admin --savemasterpassword=true --instanceport 8080 petstore

        Please enter the admin password>adminpwd
        Please enter the admin password again>adminpwd
        Please enter the master password>masterpwd
        Please enter the master password again>masterpwd
	Using port 8282 for Admin.
	Using port 8080 for HTTP Instance.
	Using default port 7676 for JMS.
	Using default port 3700 for IIOP.
	Using default port 8181 for HTTP_SSL.
	Using default port 3820 for IIOP_SSL.
	Using default port 3920 for IIOP_MUTUALAUTH.
	Using default port 8686 for JMX_ADMIN.
	Domain petstore created.

You will then see the %GLASSFISH_HOME%/domains/petstoredirectory

  • (If later you want to delete this domain, enter ant -f admin.xml delete-domain or asadmin delete-domain petstore)
  • Start Glassfish by entering %PETSTORE_HOME%/ant -f admin.xml start-domain
  • Check that the server is running by going to http://localhost:8080/

If the server doesn’t start up, check the log file at %GLASSFISH_HOME%/domains/petstore/logs/server.log

  • Start the database with %PETSTORE_HOME%/ant -f admin.xml start-db
[exec] Database started in Network Server mode on host localhost and port 1527.
     ...
     [exec] Command start-database executed successfully.
  • Setup GlassFish with the task %PETSTORE_HOME%/ant -f admin.xmlsetup. This will execute the following tasks :
    • Create a connection pool to the database (%PETSTORE_HOME%/ant -f admin.xml create-connection-pool)
    • Create the database (%PETSTORE_HOME%/ant -f admin.xml ping-connection-pool). You will se the %GLASSFISH_HOME%/javadb/petstoreDB directory
    • Create a datasource (%PETSTORE_HOME%/ant -f admin.xml create-datasource)
    • Create JMS ressources:
      • A ConnectionFactory (%PETSTORE_HOME%/ant -f admin.xml create-jms-connection-factory)
      • A JMS Topic (%PETSTORE_HOME%/ant -f admin.xml create-jms-topic)
    • Create the applications logger that use the java.util.logging API (%PETSTORE_HOME%/ant -f admin.xml set-loggers)

Check the configuration

Check that the configuration is ok using the %PETSTORE_HOME%/ant -f admin.xml listtask. This will execute the following tasks :

  • Checks the petstorePool connection pool (ant -f admin.xml list-connection-pool)
[exec] CallFlowPool
         [exec] TimerPool
         [exec] DerbyPool
         [exec] petstorePool
  • Check the petstoreDS datasource (%PETSTORE_HOME%ant -f admin.xml list-datasource)
[exec] jdbc/TimerPool
         [exec] jdbc/CallFlowPool
         [exec] jdbc/default
         [exec] jdbc/petstoreDS
    • you can also use the admin console (Resources>JDBC>JDNC Resources)
  • Check the JMS ressources (%PETSTORE_HOME%ant -f admin.xml list-jms-resources)
[exec] jms/queue/client
         [exec] jms/topic/order
         [exec] jms/petstoreConnectionFactory
    • you can also use the admin console (Resources>JMS Resources>Connection Factories and Destination Resources)
  • To check that the loggers are ok you have to
    • Go to the admin console http://localhost:8282 (admin/adminpwd)
    • Click on “Application Server”
    • Click on the “Logging” tab
    • On the logging page, click on the “Log Levels” tab
    • At the bottom of the page you’ll see the “Additional Module Log Level Properties” section
    • You should see the following loggers : com.yaps.petstore, com.barkbank et com.petex

Deploy the application

Now that the servers are setup, you have to deploy the applications on the server.

Déploy the BarkBank application

  • Build the application with %PETSTORE_HOME%/ant barkbank-build. This will compile the application, generate the web services les artefacts and package the application in the %PETSTORE_HOME%/BarkBank/build/barkbank.war file
  • Deploy the application on the server with %PETSTORE_HOME%/ant barkbank-deploy. To check that the deployment is done go to http://localhost:8080/barkbank/

Déployez l’application PetEx

  • Build the application with %PETSTORE_HOME%/ant petex-build.This will compile the application, generate the web services les artefacts and package the application in the %PETSTORE_HOME%/PexEx/build/petex.war file
  • Deploy the application on the server with %PETSTORE_HOME%/ant petex-deploy. To check that the deployment is done go to http://localhost:8080/petex/

Déployez l’application Yaps

  • Build the application with %PETSTORE_HOME%/ant yaps-build. This will compile the application, generate the web services les artefacts and package the application in the %PETSTORE_HOME%/Yaps/build directory
  • Deploy the application on the server with %PETSTORE_HOME%/ant yaps-deploy. This task deploys the application and adds data to the database. To check that the deployment is done go to http://localhost:8080/petstore/

Use the application

Once the three applications deployed, you can go to http://localhost:8080/petstore/.Look at the animals catalog, create your own account or log on as job/job. Buy some pets, create an order and you’ll use the external web services of BarkBank (to validate bredit cards) and PetEx.

To run the Swing application use the %PETSTORE_HOME%/ant run-clienttask

Stop/Start the servers

  • Derby
    • ant -f admin.xml start-db
    • ant -f admin.xml stop-db
  • GlassFish
    • ant -f admin.xml start-domain
    • ant -f admin.xml stop-domain

2 thoughts on “Install the application

  1. j’arrive pas à importer le projet Yaps dans Netbeans si quelqu’un peu m’aider à trouver la solution merci d’ance

Leave a Reply