0% found this document useful (0 votes)
164 views

Java EE 5.0 App Development On Geronimo Simplified Using Eclipse

This document provides an overview of using Eclipse and the Web Tools Platform (WTP) to develop Java EE applications that are deployed to the Apache Geronimo application server. It begins with introductions to Eclipse, WTP, and Geronimo. It then outlines hands-on exercises to setup the IDE, create a simple web application with a JSP, deploy it to the Geronimo server, and view it in a web browser. Future exercises will develop more complex Java EE applications and debug them using the IDE tools.

Uploaded by

Gbenga Cruz
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
164 views

Java EE 5.0 App Development On Geronimo Simplified Using Eclipse

This document provides an overview of using Eclipse and the Web Tools Platform (WTP) to develop Java EE applications that are deployed to the Apache Geronimo application server. It begins with introductions to Eclipse, WTP, and Geronimo. It then outlines hands-on exercises to setup the IDE, create a simple web application with a JSP, deploy it to the Geronimo server, and view it in a web browser. Future exercises will develop more complex Java EE applications and debug them using the IDE tools.

Uploaded by

Gbenga Cruz
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 70

Java EE 5.

0 App Development on
Geronimo simplified using Eclipse

Shiva Kumar H.R.


IBM India Software Labs, Bangalore
[email protected] / [email protected]
Agenda
• Apache Geronimo - An Introduction

• Eclipse & Web Tools Platform


– Eclipse - Introduction, Java Development Tools
– Web Tools Platform, Geronimo Eclipse Plug-in

• Hands-on Exercises - 1
– IDE Setup
– Start Geronimo server
– Create a new Web application with a single JSP
– Deploy it on to Server
– Make changes to the Web application and Redeploy
– Undeploy Web application
– Stop Geronimo Server
Agenda
• Hands-on Exercises - 2: Develop a simple Java EE application
– Application Overview & Design
– Create & populate Database Tables using Admin Console.
– Create EJB project
• Create Database Connection Profile
• Create JPA Entities
• Create Stateless Session Bean
– Create Web project
• Create Servlet & JSPs
– Create Enterprise Application Project and add EJB & Web projects into it.
– Create Geronimo Deployment Plan
– Deploy & Run the Java EE application

• Hands-on Exercises - 3: Debug the Java EE application

• Web Service Tools


Agenda
• Apache Geronimo - An Introduction

• Eclipse & Web Tools Platform


– Eclipse - Introduction, Java Development Tools
– Web Tools Platform, Geronimo Eclipse Plug-in

• Hands-on Exercises - 1
– IDE Setup
– Start Geronimo server
– Create a new Web application with a single JSP
– Deploy it on to Server
– Make changes to the Web application and Redeploy
– Undeploy Web application
– Stop Geronimo Server
Apache Geronimo
• Open source J2EE/Java EE
Application Server developed by the
Apache Software Foundation.

• Brings together leading technologies


from the broad open source
community to support J2EE/Java EE.
http://geronimo.apache.org/

• Small footprint and highly


customizable.
Geronimo as a J2EE 1.4 compliant server*

*Source: IBM developerWorks article by author Sing Li


http://www-128.ibm.com/developerworks/java/library/j-geron1/index.html
Geronimo as a Java EE 5.0 compliant server*

*this slide needs to be updated


Agenda
• Apache Geronimo - An Introduction

• Eclipse & Web Tools Platform


– Eclipse - Introduction, Java Development Tools
– Web Tools Platform, Geronimo Eclipse Plug-in

• Hands-on Exercises - 1
– IDE Setup
– Start Geronimo server
– Create a new Web application with a single JSP
– Deploy it on to Server
– Make changes to the Web application and Redeploy
– Undeploy Web application
– Stop Geronimo Server
Eclipse & Web Tools Platform
An Integrated development environment
(IDE) for creating, deploying, and debugging
directly against Geronimo
Eclipse - Introduction
• Eclipse is an open source community
whose projects are focused on building an
extensible development platform,
runtimes and application frameworks for
building, deploying and managing
software across the entire software
lifecycle. http://www.eclipse.org/

• Many people know it, and hopefully love


it, as a Java IDE but Eclipse is much
more than a Java IDE.
Java Development Tools*
• Code editing features - Code completion, Syntax coloring, Error
markers & Quick fixes, Automatic indent, Code folding (expand
and collapse).

• Code refactoring - Rename fields, methods, classes, interfaces, and


packages, as well as add get/set methods for fields.

• Source-level debugging - Set absolute/conditional breakpoints, Step


into method calls as well as over them, Jump out of methods, Run
to cursor.

• Visual code browsers like Project Explorer & Hierarchy views.

*Source: Eric J. Bruno’s article “NetBeans 4.1 & Eclipse 3.1”


http://www.ddj.com/dept/java/184406194
Eclipse Web Tools Platform*
• WTP supports J2EE/Java EE development.

• WTP extends Eclipse along two dimensions, namely


execution environments and artifact types.

• The execution environment dimension defines where


code runs.
– WTP extends Eclipse by adding servers as new execution
environments.
– Servers include both J2EE/Java EE and Database servers.

*Source: Arthur Ryman’s article “Eclipse: The Story of Web Tools Platform 0.7”
http://java.sys-con.com/read/111212.htm
Eclipse Web Tools Platform
• The development artifact dimension defines what developers create.

– New artifact types encountered in J2EE/Java EE development -


HTML, CSS, JavaScript, XHTML, JSP, XML, XSD, WSDL,
SQL, and all the J2EE/Java EE deployment descriptors.

– Each artifact type has associated with it builders, creation


wizards, syntax-aware editors, validators, semantic search
extensions, and refactoring support.

– Editors provide first-class programmer assistance such as code


completion, syntax coloring, error markers, and quick fixes.
Eclipse Web Tools Platform
• Key design goal of WTP - all of the functions that Eclipse users
have come to expect from Java source code will "just work" for
the new artifacts.

– For example, if I select a JSP, I can Run or Debug it.

– Similarly, the Debug command will run my J2EE/Java EE


server in debug mode and the standard Eclipse Debugger will
let me step through my JSP source code.

– My JSP editor will provide code completion for both JSP tags
and inlined Java scriptlets.
Geronimo Eclipse Plug-in
• Extends WTP’s server tools to add Apache Geronimo
as a new server type.

• Provides form based editors for Geronimo


Deployment Plans.
Eclipse WTP without Geronimo Eclipse Plug-in Eclipse WTP with Geronimo Eclipse Plug-in
Agenda
• Apache Geronimo - An Introduction

• Eclipse & Web Tools Platform


– Eclipse - Introduction, Java Development Tools
– Web Tools Platform, Geronimo Eclipse Plug-in

• Hands-on Exercises - 1
– IDE Setup
– Start Geronimo server
– Create a new Web application with a single JSP
– Deploy it on to Server
– Make changes to the Web application and Redeploy
– Undeploy Web application
– Stop Geronimo Server
IDE Setup
1. Download & Install Geronimo v2.0.1 from
http://geronimo.apache.org/downloads.html
– “Geronimo 2.0.1 with Tomcat 6 (zip)” is used in this presentation.

2. Download and install WTP v2.0 all-in-one-sdk from


http://download.eclipse.org/webtools/downloads/drops/R2.0/R-2.0-200706260303/
– This includes Eclipse SDK v3.3, WTP v2.0 and WTP’s pre-requisites
namely EMF, GEF & DTP.
– “wtp-all-in-one-sdk-R-2.0-200706260303-win32.zip” is used in this
presentation.

3. Download and install Geronimo Eclipse Plug-in v2.0 as per the


instructions at http://geronimo.apache.org/development-tools.html

Finally start eclipse with “-clean” option (i.e. “eclipse -clean”) and switch
to “Java EE” perspective (Window -> Open Perspective -> Other ->
Java EE -> OK).

*JVM used: Sun JDK 1.5.0_11


Add Geronimo runtime into WTP
1. Click on the “Servers” tab at the bottom half of Eclipse window.

2. In the “Servers” view, right click and select “New->Server” from the
context menu.

3. In the “New Server” wizard that comes up, select “Apache Geronimo
v2.0 Server” and click “Next”.

4. Click “Browse” and specify the root directory of Apache Geronimo


v2.0.1 installation.

5. Click “Finish” to complete adding new server runtime. “Apache


Geronimo v2.0 Server at ..” should now appear in the “Servers” view.
Add Geronimo runtime into WTP

Step 3 Step 4
Start Geronimo server
1. In the “Servers” view select the server you just configured, right
click and select “Start” from the context menu.

2. You will be switched to the “Console” view while the server is


starting. Verify that you are switched back to the “Servers” view
and that the “State” of your server now says “Started”.
Create a new Web application
1. From the Eclipse menu select “File-
>New->Other”

2. Expand “Web” and select “Dynamic


Web Project” as shown. Click “Next”.

3. Enter “SimpleWeb” as the project name and make sure “Apache


Geronimo v2.0” is selected as the “Target runtime”.

4. Click “Next”. Make sure the “Geronimo Deployment” Project


Facet is selected.

5. Click “Next”. Accept the default web module settings and click
“Finish”.
Create a simple JSP
1. From the “Project Explorer”
view, expand “SimpleWeb”
project and select “WebContent”
folder. Right click and select
“New->JSP” from the context
menu as shown in fig.

2. Name the JSP “index.jsp” and click “Finish”.

3. This brings up the JSP editor. Enter the text “Hello World”
between the <body> </body> HTML tags.

4. Type “Ctrl+S” to save the changes. Leave the editor window


open
Deploy the Web application

1. From the Eclipse menu select “Window->Web Browser” and then


select either “Internet Explorer” or “Firefox”. Without this step
Eclipse will use its Internal browser which takes up a lot of valuable
screen space within your Eclipse IDE.

2. From the “Project Explorer” view expand “SimpleWeb” and


“WebContent”.

3. Select “index.jsp” , right click and select “Run As -> Run on Server”

4. Accept the defaults in the “Run on Server” dialog and click “Finish”.

5. A browser window should appear with the contents of “index.jsp”.


Leave the browser window open.
Make changes to the Web
application and redeploy
1. Go back to the JSP editor and change “Hello World” to
something else (e.g. Hello Underworld).

2. Type Ctrl+S to save the changes.

3. Go to the “Servers” view and select your server. If the “Status”


column still* says “Republish”, right click and select “Publish”
from the context menu. Verify that the State of the server
changes to “Synchronized”.

4. Go back to the browser window that you used to test the JSP
initially and reload the page. Verify that the changes you made to
the JSP are reflected in the browser.

* WTP detects changes and invokes auto republish.


Undeploy web application
1. Go to the “Servers” view and select your server. Right click and
select “Add and Remove Projects” from the context menu

2. In the resulting dialog click on “Remove all” and then click on


“Finish”

Stop Geronimo server


1. Go back to the “Servers” view and select your server. Right click
and select “Stop” from the context menu.
Agenda
• Hands-on Exercises - 2: Develop a simple Java EE application
– Application Overview & Design
– Create & populate Database Tables using Admin Console.
– Create EJB project
• Create Database Connection Profile
• Create JPA Entities
• Create Stateless Session Bean
– Create Web project
• Create Servlet & JSPs
– Create Enterprise Application Project and add EJB & Web projects into it.
– Create Geronimo Deployment Plan
– Deploy & Run the Java EE application

• Hands-on Exercises - 3: Debug the Java EE application

• Web Service Tools


Application Overview &
Design
EJB sample application from Apache Geronimo v2.0 Samples
http://cwiki.apache.org/GMOxDOC20/ejb-sample-application.html
Banking Application – Overall Architecture
Banking Application – Database Design

Database

Embedded
Apache Derby
Banking Application - Implementation

customer_info.jsp
JSP &
index.jsp CustomerServiceServlet Servlets
error.jsp

Stateless
BankManagerFacadeBean Session Bean

Customer Account JPA Entities


Agenda
• Hands-on Exercises - 2: Develop a simple Java EE application
– Application Overview & Design
– Create & populate Database Tables using Admin Console.
– Create EJB project
• Create Database Connection Profile
• Create JPA Entities
• Create Stateless Session Bean
– Create Web project
• Create Servlet & JSPs
– Create Enterprise Application Project and add EJB & Web projects into it.
– Create Geronimo Deployment Plan
– Deploy & Run the Java EE application

• Hands-on Exercises - 3: Debug the Java EE application

• Web Service Tools


Create & populate Database using
Admin Console
1. Start Geronimo server as before.

2. Open Admin Console, by right clicking on your server in Servers view and
selecting “Launch Geronimo Console”. Login with appropriate credentials*.

3. In “Console Navigation” portlet of Admin Console, click on “DB Manager”


under “Embedded DB”.

4. In “Create DB” textbox, type “BankDB” and click “Create”. This creates a
new Embedded Database by name “BankDB”. Make sure “Run SQL” view
displays the Result as “Database created: BankDB” (scroll down to see
Result).

5. Select “BankDB” next to “Use DB”, then copy the following SQL statements
into the textbox below and click “Run SQL”. This creates the required Tables
in “BankDB” and populates them. Make sure “Run SQL” view displays
Result as “SQL command/s successful”.

*default Username: system, Password: manager


Create & populate Database using
Admin Console
CREATE TABLE Customer(
customerId VARCHAR(255) PRIMARY KEY,
name VARCHAR(255));

CREATE TABLE Account(


accountNumber VARCHAR(255) PRIMARY KEY,
accountType VARCHAR(255),
balance DOUBLE,
customerId VARCHAR(255),
FOREIGN KEY (customerId) REFERENCES customer);

INSERT INTO Customer(customerId, name)


VALUES('12345','Panini');
INSERT INTO Account(accountNumber, accountType, balance, customerId)
VALUES('1234567890','Savings',1005.35,'12345');
INSERT INTO Account(accountNumber, accountType, balance, customerId)
VALUES('2345678901','Current',999.95,'12345');
Agenda
• Hands-on Exercises - 2: Develop a simple Java EE application
– Application Overview & Design
– Create & populate Database Tables using Admin Console.
– Create EJB project
• Create Database Connection Profile
• Create JPA Entities
• Create Stateless Session Bean
– Create Web project
• Create Servlet & JSPs
– Create Enterprise Application Project and add EJB & Web projects into it.
– Create Geronimo Deployment Plan
– Deploy & Run the Java EE application

• Hands-on Exercises - 3: Debug the Java EE application

• Web Service Tools


Create Database Connection Profile
1. Click on “Data Source Explorer” tab at the bottom half of Eclipse window.

2. Right Click on “Databases” and select “New” from the context menu.

3. In the “New Connection Profile” wizard that comes up, select “Derby
Embedded Database” and click “Next”.

4. Enter a “Name” for the connection profile, say “BankDBProfile”, and


click “Next”.
5. Click the ellipsis (…) button just
below “Select a driver from the
drop-down”, to create a new
Driver definition.
Create Database Connection Profile
6. In the “Driver Definitions” wizard that comes up, click “Add”.

7. In the “New Driver Definition” wizard that comes up, select “Database ->
Derby -> 10.2 -> Derby Embedded JDBC Driver”, make sure “Edit New
Driver Definition Immediately” is selected and click “OK”.

8. An “Edit Driver Definition” wizard comes up. Remove the default


“derby.jar” by selecting it under “Driver File(s)” and clicking “Remove
Jar/Zip”.

9. Add “derby-10.2.2.0.jar” shipped with Geronimo, by clicking on “Add


Jar/Zip” and then pointing to “<Geronimo
Home>\repository\org\apache\derby\derby\10.2.2.0\ derby-10.2.2.0.jar”.

10. Under “Properties” table, edit “Connection URL” value and change it to
“jdbc:derby:<Geronimo-Home>\var\derby\BankDB”, where <Geronimo-
Home> should be replaced with the path to your Geronimo root directory.
Change “Database Name” to “BankDB”. Finally Click “OK”.
Create Database Connection Profile

Embedded Derby’s Driver Definition


Create Database Connection Profile
11. Back in the “Driver Definitions” wizard, select the just added “Derby ->
10.2 -> Derby Embedded JDBC Driver” and click “OK”.

12. Back in the initial wizard, click “Finish”.

13. “BankDBProfile” should now appear under “Databases” in “Data Source


Explorer” view.

14. Right click on “BankDBProfile” and click “Connect”. If connect fails,


stop* Geronimo server and try again. Connect should now succeed.

*when Geronimo is already running, connecting to


its embedded database from outside might fail
Agenda
• Hands-on Exercises - 2: Develop a simple Java EE application
– Application Overview & Design
– Create & populate Database Tables using Admin Console.
– Create EJB project
• Create Database Connection Profile
• Create JPA Entities
• Create Stateless Session Bean
– Create Web project
• Create Servlet & JSPs
– Create Enterprise Application Project and add EJB & Web projects into it.
– Create Geronimo Deployment Plan
– Deploy & Run the Java EE application

• Hands-on Exercises - 3: Debug the Java EE application

• Web Service Tools


Create EJB project
1. From the Eclipse menu select “File->New->Other”

2. Expand “EJB” and select “EJB Project”.

3. Enter “BankEJB” as the project name & select “Apache Geronimo v2.0”
as the “Target runtime”. Click “Next”.

4. Select “Java Persistence” under “Project Facet” and un-select*


“Geronimo Deployment”. Make sure “EJB 3.0” & “Java 5.0” are
selected. Click “Next”. Click “Next” again.

5. In “JPA Facet” page, make sure “BankDBProfile” is selected as


“Connection”, then select “Annotated classes must be listed in
persistence.xml”, unselect “Create orm.xml” and finally click “Finish”.

*selecting “Geronimo Deployment” will create “openejb-jar.xml”


which is not required for EJB 3.0 (JPA) entities
Create JPA Entities
1. In the “Project Explorer” view right click on “BankEJB” project and select
“JPA Tools -> Generate Entities”.

2. Make sure “BankDBProfile” is selected as “Connection” and select “APP”


as the “Schema”. Click “Next”.

3. Specify “Package” name as “org.apache.geronimo.samples.bank.ejb”.


Select both “Account” and “Customer” tables and click “Finish”. You will
see that JPA entities for those database tables are now created.

4. In “Project Explorer” view, expand “BankEJB -> ejbModule -> META-


INF” and double-click on “persistence.xml” to open it in an editor.

5. Replace* “persistence.xml” contents as shown next and press “Ctrl + S” to


save the changes. Press “Ctrl + W” to close the editor.

*In case you are unable to edit “persistence.xml” contents,


then try restarting your Eclipse!. Seems to be a bug.
Create JPA Entities
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">

<persistence-unit name="BankPU">
<description>Entity Beans for Bank</description>
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>BankPool</jta-data-source>
<non-jta-data-source>BankPool</non-jta-data-source>
<class>org.apache.geronimo.samples.bank.ejb.Account</class>
<class>org.apache.geronimo.samples.bank.ejb.Customer</class>
<properties>
<property name="openjpa.jdbc.SynchronizeMappings" value="false" />
</properties>
</persistence-unit>
</persistence>
Agenda
• Hands-on Exercises - 2: Develop a simple Java EE application
– Application Overview & Design
– Create & populate Database Tables using Admin Console.
– Create EJB project
• Create Database Connection Profile
• Create JPA Entities
• Create Stateless Session Bean
– Create Web project
• Create Servlet & JSPs
– Create Enterprise Application Project and add EJB & Web projects into it.
– Create Geronimo Deployment Plan
– Deploy & Run the Java EE application

• Hands-on Exercises - 3: Debug the Java EE application

• Web Service Tools


Create Session Bean Interface
1. In the “Project Explorer” view, right click on “BankEJB” project and
select “New -> Interface”.

2. Specify “Package” name as “org.apache.geronimo.samples.bank.ejb” and


interface “Name” as “BankManagerFacadeLocal”. Click “Finish”.

3. Add following business methods inside the interface:


public Collection<Account> getAccountInformation(String customerId);
public Customer getCustomer(String customerId);

4. Press “Ctrl + Shift + O” to organize imports, “Ctrl + S” to save changes


and “Ctrl + W” to exit.
Create Session Bean
1. In “Project Explorer” view, right click on “BankEJB” project and select
“New -> Class”.

2. Specify “Package” name as “org.apache.geronimo.samples.bank.ejb” and


class “Name” as “BankManagerFacadeBean”.

3. Click “Add” next to “Interfaces”, type & select


“BankManagerFacadeLocal” and click “OK”. Finally click “Finish”.

4. Add “@Stateless” annotation to “BankManagerFacadeBean” class as


below:
@Stateless
public class BankManagerFacadeBean implements BankManagerFacadeLocal {

5. Create a class variable for JPA’s EntityManagerFactory as below:


@PersistenceUnit(unitName="BankPU")
protected EntityManagerFactory emf;
Create Session Bean
6. Update business methods of Session Bean as below:
public Collection<Account> getAccountInformation(String customerId) {
Customer customer = getCustomer(customerId);
if(customer != null) {
return customer.getAccountCollection();
}
return null;
}
public Customer getCustomer(String customerId) {
EntityManager em = emf.createEntityManager();
Customer customer = (Customer)em.find(Customer.class, customerId);
em.close();
return customer;
}

7. Press “Ctrl + Shift + O” to organize imports, “Ctrl + S” to save changes & “Ctrl +
W” to close editor.
Agenda
• Hands-on Exercises - 2: Develop a simple Java EE application
– Application Overview & Design
– Create & populate Database Tables using Admin Console.
– Create EJB project
• Create Database Connection Profile
• Create JPA Entities
• Create Stateless Session Bean
– Create Web project
• Create Servlet & JSPs
– Create Enterprise Application Project and add EJB & Web projects into it.
– Create Geronimo Deployment Plan
– Deploy & Run the Java EE application

• Hands-on Exercises - 3: Debug the Java EE application

• Web Service Tools


Create Web Project & Servlet
1. Create a Dynamic Web project with name “BankWeb” as below: “File ->
New -> Other -> expand Web -> select Dynamic Web Project -> specify
Project name: BankWeb -> Next -> unselect* Geronimo Deployment ->
click Finish”.

2. In the “Project Explorer” view right click on “BankWeb” project and select
“New” -> “Servlet”.

3. Specify Java package as “org.apache.geronimo.samples.bank.web” and


Class name as “CustomerServiceServlet”. Click “Next”.

4. In “URL Mappings” select “/CustomerServiceServlet” and click “Edit”.


Change the URL mapping to “/customer_info”. (JSPs that we will copy
next are using this URL and hence this change). Click “OK”.

5. Click “Finish”. “CustomerServiceServlet.java” will now be created and


elements for it will be added in “web.xml”.

*If Geronimo Deployment is selected, geronimo-web.xml will be created.


In that case remember to update <context-root> inside geronimo-web.xml.
Create Web Project & Servlet
6. Add a class variable in the servlet to hold EJB reference to Session Bean as shown
below:
@EJB
private BankManagerFacadeLocal bm = null;

7. Update the doGet() method of CustomerServiceServlet as shown next:


protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
String path = "/jsp/error.jsp";
String customerCode = request.getParameter("customerCode");

Collection<Account> accountList = bm.getAccountInformation(customerCode);


Customer customer = bm.getCustomer(customerCode);

if (accountList != null && customer != null) {


request.setAttribute("accountList", accountList);
request.setAttribute("customerCode", customerCode);
request.setAttribute("customerName", customer.getName());
path = "/jsp/customer_info.jsp";
}
getServletContext().getRequestDispatcher(path).forward(request, response);
}
Create Web Project & Servlet
8. Forward call to doPost() method to doGet() as below:

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,


IOException {
doGet(request, response);
}

9. To resolve references to EJBs referred in doGet() method add “BankEJB”


project into the build path of “BankWeb” by “Right clicking on BankWeb
project -> Properties -> Java Build Path -> Projects -> Add -> select
BankEJB -> OK -> OK”.

10. Press “Ctrl + Shift + O” to organize imports, “Ctrl + S” to save changes &
“Ctrl + W” to close editor.
Copy JSPs into Web Project
1. In Project Explorer view, expand “BankWeb” and right click on “WebContent” folder
and click “Import”.

2. Expand “General” and select “File System”. Click “Next”.

3. Click “Browse” next to “From directory” and select the directory where you have
extracted “BankExample.zip”*. Click “OK”.

4. On the left side of “Import” wizard, expand “Bank Example”, select & check “jsp”
folder.

5. Make sure “Into folder” says “BankWeb/WebContent”.

6. Click “Finish”. You will observe that a “jsp” folder is created in “WebContent”
directory of “BankWeb” project and following three files are copied inside of that
“jsp” folder: “index.jsp”, “customer_info.jsp” and “error.jsp”.

7. Import from File System can also be done by dragging “jsp” folder from “Windows
Explorer” and dropping it on “WebContent” directory of “BankWeb” project.

*Download BankExample.zip from here


Update “web.xml”
1. In “Project Explorer” view expand “BankWeb” -> “WebContent” ->
“WEB-INF” and double click on “web.xml” to open it in an editor.

2. Update <welcome-file-list> element as below and press “Ctrl +S” to


save changes.
<welcome-file-list>
<welcome-file>jsp/index.jsp</welcome-file>
</welcome-file-list>
Agenda
• Hands-on Exercises - 2: Develop a simple Java EE application
– Application Overview & Design
– Create & populate Database Tables using Admin Console.
– Create EJB project
• Create Database Connection Profile
• Create JPA Entities
• Create Stateless Session Bean
– Create Web project
• Create Servlet & JSPs
– Create Enterprise Application Project and add EJB & Web projects into it.
– Create Geronimo Deployment Plan
– Deploy & Run the Java EE application

• Hands-on Exercises - 3: Debug the Java EE application

• Web Service Tools


Create Enterprise Application Project
1. From Eclipse menu, select “File” -> “New” -> “Project…”.

2. Expand “J2EE” and select “Enterprise Application Project”. Click “Next”.

3. Specify “Project name” as “Bank”. Click “Next”. Click “Next” again.

4. In “J2EE Modules to Add to the EAR” page, select and check “BankEJB”
and “BankWeb” modules. Click “Finish”.

5. In “Project Explorer” view expand “Bank -> EARContent”. Right click on


“META-INF” and select “New -> File”. Enter “File name” as
“application.xml”* and click “Finish”.

6. Replace the contents of “application.xml” as shown next. Click “Ctrl + S” to


save changes and “Ctrl + W” to close editor.

*Geronimo will throw errors if “application.xml” is not present.


Create Enterprise Application Project
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/application_5.xsd"
version="5">
<description>Geronimo Samples, Bank</description>
<display-name>Bank</display-name>

<module>
<web>
<web-uri>BankWeb.war</web-uri>
<context-root>/Bank</context-root>
</web>
</module>
<module>
<ejb>BankEJB.jar</ejb>
</module>
</application>
Agenda
• Hands-on Exercises - 2: Develop a simple Java EE application
– Application Overview & Design
– Create & populate Database Tables using Admin Console.
– Create EJB project
• Create Database Connection Profile
• Create JPA Entities
• Create Stateless Session Bean
– Create Web project
• Create Servlet & JSPs
– Create Enterprise Application Project and add EJB & Web projects into it.
– Create Geronimo Deployment Plan
– Deploy & Run the Java EE application

• Hands-on Exercises - 3: Debug the Java EE application

• Web Service Tools


Create Geronimo Deployment Plan
1. In “Project Explorer” view expand “Bank” -> “EARContent” -> “META-
INF” and double click* on “geronimo-application.xml” to open it in an
editor. Click on “Source” tab to switch to edit source.

2. Replace the contents of this file with the contents provided in “geronimo-
application.xml” file of “BankExample.zip”.

You will notice that this deployment plan defines a database pool by name
“BankPool” which was referenced by Persistence Unit in “persistence.xml”.

Please note that the Form Based Editors for Geronimo Deployment Plans provided
by Geronimo Eclipse Plug-in is currently limited in its functionality and as
such, Geronimo Deployment Plans have to be created manually.

You can refer Aaron Mulder’s book on


“Apache Geronimo Development and Deployment” for detailed information
on creating Geronimo Deployment Plans.

*Geronimo Eclipse Plug-in v2.0 currently has no support for v2.0 of Geronimo deployment plans. Hence
you might face error while opening them. Please use “Open With -> XML Editor” for the time being.
Agenda
• Hands-on Exercises - 2: Develop a simple Java EE application
– Application Overview & Design
– Create & populate Database Tables using Admin Console.
– Create EJB project
• Create Database Connection Profile
• Create JPA Entities
• Create Stateless Session Bean
– Create Web project
• Create Servlet & JSPs
– Create Enterprise Application Project and add EJB & Web projects into it.
– Create Geronimo Deployment Plan
– Deploy & Run the Java EE application

• Hands-on Exercises - 3: Debug the Java EE application

• Web Service Tools


Deploy and Run the Java EE App
1. Start Geronimo if it is not already started.

2. Go to “Servers” view. Right click on your server and click “Add and
Remove Projects…”.

3. Select “Bank” under “Available projects:” and click “Add >”. Click
“Finish”. The EAR will now be deployed onto server. Wait until server
“State” is shown as “Synchronised” (You might have to switch back to the
“Servers” view to see the server “State”).

4. Open http://localhost:8080/Bank in a Browser.

5. Enter “Customer Id:” as “12345” and press “View”. Customer Account


Information will now be displayed.

6. Click “Home”. Enter “Customer Id:” as “6789” and press “View”. An error
page will be shown as this Customer doesn’t exist in database.
Agenda
• Hands-on Exercises - 2: Develop a simple Java EE application
– Application Overview & Design
– Create & populate Database Tables using Admin Console.
– Create EJB project
• Create Database Connection Profile
• Create JPA Entities
• Create Stateless Session Bean
– Create Web project
• Create Servlet & JSPs
– Create Enterprise Application Project and add EJB & Web projects into it.
– Create Geronimo Deployment Plan
– Deploy & Run the Java EE application

• Hands-on Exercises - 3: Debug the Java EE application

• Web Service Tools


Debug the Java EE application
1. In “Project Explorer” view expand “BankWeb” -> “Java Resources: src” ->
“org.apache.geronimo.samples.bank.web” and double click on
“CustomerServiceServlet.java” to open it in an editor.

2. In the left bar of Editor window, double click on some java code (say the first
executable line of doGet() method). This will create a line break point at that code.

3. Go back to “Servers” view, right click on your server and select “Debug”. This will
re-start your server in Debug mode.

4. Open http://localhost:8080/Bank in a Browser. Enter “Customer Id:” as “6789” and


press “View”.

5. Eclipse window will pop up asking for Perspective Switch to Debug perspective.
Click Yes. Eclipse will now look as shown in next page.
Debug the Java EE application
6. You can now step through our Servlet code, viewing and changing variable values
as you go.

7. Select following line, right click and select “Run to Line”. You will see that code
is run up to that line.
“String customerCode = request.getParameter("customerCode");

8. Click “Step Over” icon in the “Debug view” to execute the above line

9. In the “Variables” view, select “customerCode” variable and click in the “Value”
column. You will see that the value of “customerCode” can now be changed.
Change the value number from “6789” to “12345”. Click “Enter”

10. Back in the “Debug” view, click the green icon to continue execution.

11. In the browser you will observe that Account Information for “Customer Id:
12345” is displayed.
Agenda
• Hands-on Exercises - 2: Develop a simple Java EE application
– Application Overview & Design
– Create & populate Database Tables using Admin Console.
– Create EJB project
• Create Database Connection Profile
• Create JPA Entities
• Create Stateless Session Bean
– Create Web project
• Create Servlet & JSPs
– Create Enterprise Application Project and add EJB & Web projects into it.
– Create Geronimo Deployment Plan
– Deploy & Run the Java EE application

• Hands-on Exercises - 3: Debug the Java EE application

• Web Service Tools


Eclipse WTP - Web Service tools
• WSDL editor - both a source editor and a graphical editor.

• Web Service Explorer that lets you search and publish to UDDI
registries, and dynamically test WSDL-based Web Services.

• Web Service Wizard that ties together the full development


lifecycle. It lets you deploy Java classes as Web Services, generate
server and client code from WSDL, and generate test clients, as
well as being integrated with the Web Service Explorer for
publishing and discovery.

• Web Service Interoperability (WS-I) Test Tools that lets you


validate WSDL and SOAP for compliance with the WS-I profiles.

• TCP/IP monitor that's very handy for debugging HTTP traffic.


Q&A

Shiva Kumar H.R.


[email protected] / [email protected]
References
• IBM developerWorks article by author Sing Li – “Geronimo! Part 1: The
J2EE 1.4 engine that could”
– http://www-128.ibm.com/developerworks/java/library/j-geron1/index.html

• Arthur Ryman’s article “Eclipse: The Story of Web Tools Platform 0.7”
at Java Developer's Journal
– http://java.sys-con.com/read/111212.htm

• Eric J. Bruno’s article “NetBeans 4.1 & Eclipse 3.1” at Dr. Dobb's Portal
– http://www.ddj.com/dept/java/184406194

• IBM GetStarted with Application Deployment on WebSphere Application


Server Community Edition
– http://www-306.ibm.com/software/webservers/appserv/community/services/

• Apache Geronimo v2.0 EJB sample application


– http://cwiki.apache.org/GMOxDOC20/ejb-sample-application.html

You might also like