Java EE 5.0 App Development On Geronimo Simplified Using Eclipse
Java EE 5.0 App Development On Geronimo Simplified Using Eclipse
0 App Development on
Geronimo simplified using Eclipse
• 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 - 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.
• 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/
*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.
– 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.
• 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.
Finally start eclipse with “-clean” option (i.e. “eclipse -clean”) and switch
to “Java EE” perspective (Window -> Open Perspective -> Other ->
Java EE -> OK).
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”.
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.
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.
3. This brings up the JSP editor. Enter the text “Hello World”
between the <body> </body> HTML tags.
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”.
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.
Database
Embedded
Apache Derby
Banking Application - Implementation
customer_info.jsp
JSP &
index.jsp CustomerServiceServlet Servlets
error.jsp
Stateless
BankManagerFacadeBean Session Bean
2. Open Admin Console, by right clicking on your server in Servers view and
selecting “Launch Geronimo Console”. Login with appropriate credentials*.
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”.
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”.
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”.
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
3. Enter “BankEJB” as the project name & select “Apache Geronimo v2.0”
as the “Target runtime”. Click “Next”.
<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
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
2. In the “Project Explorer” view right click on “BankWeb” project and select
“New” -> “Servlet”.
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”.
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.
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.
4. In “J2EE Modules to Add to the EAR” page, select and check “BankEJB”
and “BankWeb” modules. Click “Finish”.
<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
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.
*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
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”).
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
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.
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
• Web Service Explorer that lets you search and publish to UDDI
registries, and dynamically test WSDL-based Web Services.
• 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