lundi 5 mai 2008

Deploying Java Pet Store 2.0 on JBOSS using Eclipse IDE

Introduction:

The java Pet store 2.0 is a reference application for building Ajax-enabled web application on Java EE 5. It is provided by the Java blueprints program at Sun Microsystems.
You can find more details from https://blueprints.dev.java.net/petstore/

Many people ask about running PetStore 2.0 with JBOSS server application or another JEE server that could be different from Sun server.
This tutorial is for showing you how it is possible to run PetStore 2.0 with JBoss and discuss the changes needed.

Prerequisites:

Getting started:

JBoss version 5.0, is recently a Java EE 5 compatible application server. Therefore, we don’t need to refactor the code in order to disable Java 5 features like generic types and dependency injection using annotations. However, you have to paid attention on the deployment.
Jboss recommends using the EAR file as recommended way to deploy application. So, we need to separate the persistence layer from the other layers in order to create a jar file which contains the EJB module and a war file containing the Web module.
To deploy PetStore application, you need to create three eclipse projects.

First-Step: Creation an EJB Project:


To create a new EJB project:


  1. In the J2EE perspective, select File > New > Other > EJB > EJB Project. The New EJB Project wizard opens.

  2. In the Project Name field, type a name for the EJB project.

  3. Optional: To use a different workspace directory for your EJB project, modify the settings for Project contents.

    Important: If you specify a non-default project location that is already being used by another project, the project creation will fail.

  4. In the Target runtime drop-down list, select the application server that you want to target for your development. This selection affects the compilation and runtime settings by modifying the class path entries for the project. Use the New button if a target runtime does not exist, or if you want to use a different one
Once the project is created, import entities which are located in src folder of PetStore.

Changes needed:

  • Add a persistence.xml into the META-INF directory:

<?xml version="1.0" encoding="UTF-8"?>

<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">

<persistence-unit name="PetstorePu">

<jta-data-source>java:/DefaultDS</jta-data-source>

<properties>

<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>

</properties>

</persistence-unit>

</persistence>

  • Setup the DB, using the HSQL Database Manager, by executing the petstore.sql script located under the setup/sql/javadb/
Second step: Creation a Dynamic Web project:

To create a new dynamic Web project, complete the following steps:

  • Open the J2EE perspective.

  • In the Project Explorer, right click on Dynamic Web Projects, and select New > Dynamic Web Project from the context menu. The New Dynamic Web Project wizard starts.

  • Follow the project wizard prompts.

Once the project is created, import all classes located in src folder of PetStore except entities classes.

Changes needed:

  • Remove the resource-ref in web.xml, it’s no longer needed.

  • Remove duplicated context-param « com.sun.faces.verifyObjects »

Third step: Creation an Enterprise Application project:


To create a J2EE enterprise application project:

  1. In the J2EE perspective, click File > New > Project > J2EE > Enterprise Application Project.

  2. In the Project Name field, type a name for the new project.

  3. To change the default project location, clear the Use default check box under Project contents and select a new location with the Browse button.

  4. In the Target runtime field, select the target runtime for the project. You can click the New button to create a new runtime for the project to use.

  5. On the JEE modules, select the two projects created above.

Finally, select the EAR project and click Run as>run on server.

Download :

2 commentaires:

Website designing India a dit…

Thanks for sharing your incredible thoughts on Web application development services. it is valuable.

Nickleus a dit…
Ce commentaire a été supprimé par l'auteur.