J2EE Application Development on Apache Geronimo simplified using Eclipse

nutmegactSoftware and s/w Development

Nov 10, 2012 (4 years and 9 months ago)

207 views

J2EE Application Development
on Apache Geronimo
simplified using Eclipse

Shiva Kumar H.R.

IBM India Software Labs, Bangalore

shiavhr@in.ibm.com / shivahr@gmail.com

Agenda


Geronimo


Introduction



Eclipse & Web Tools Platform


What is Eclipse?


Web Tools Platform


Geronimo Eclipse Plug
-
in



Hands
-
on Exercises


IDE Setup


Start Geronimo server


Create a new Web application & Deploy it on to Server


Make changes to the Web application and Redeploy


Undeploy Web application


Stop Geronimo server


Debug the Web application

Geronimo


An Introduction

What is Geronimo?


Open source J2EE application server
project developed by the Apache
Software Foundation.



Benefits from the efforts of
collaborative development by an
open community of Java developers
worldwide.



Brings together leading technologies
from the broad open source
community to support J2EE.


Apache
-
licensed open
source application server


Highly customizable


Small footprint (~35MB)


Community
-
driven

http://geronimo.apache.org/

*Source: IBM developerWorks article by author Sing Li

http://www
-
128.ibm.com/developerworks/java/library/j
-
geron1/index.html

Geronimo as a J2EE 1.4 compliant server*

Geronimo Key Features


J2EE 1.4 Certified


First certification with Sun Microsystems in October 2005


Geronimo v2.0 being developed will be Java EE 5.0 certified.



Option for Jetty or Tomcat as a Web Container


Geronimo supports both Jetty as well as Tomcat. Separate download packages are
available for Jetty and Tomcat.



Database Support


Comes with Apache Derby database


Also supports JDBC enabled databases using a connector framework from TranQL



Eclipse Web Tools Platform support


Integrated development environment for creating, deploying, and debugging directly
against Geronimo



Runtime customization


Advanced micro
-
kernel architecture enables runtime customization to save systems
resources and improve performance


Allows for greater flexibility in creating different server personalities like Little
-
G.

Geronimo Key Features
(continued)


Centralized configuration and control


Easy
-
to
-
use administrative console for managing and monitoring the server and related
resources



Small Footprint ~35MB


Easy access
-

downloadable in minutes


Easily embeddable in customer or ISV application stack



Liberal product license


Apache open source (ASF v2.0) license


Free to use in development, testing, and deployment



Geronimo plugins


Geronimo applications, server features, and integrated products can be distributed as
Geronimo plugins.


Plugins are easy to install, automatically download any dependencies, and do not require
server restarts.



Improved reliability for most commonly deployed applications


Web
-
tier clustering

Geronimo Admin Console

Eclipse & Web Tools Platform

An Integrated development environment
(IDE) for creating, deploying, and debugging
directly against Geronimo

What is Eclipse?

http://www.eclipse.org/

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.

Eclipse Java Development Tools (JDT)

Eclipse JDT Key Features*


Code editing features


Code completion,


Syntax coloring,


Error markers: warnings and errors indicated in real time as you write code.


Quick fixes


Code formatting, Automatic indent, Block tabbing


Code folding (expand and collapse)


Code refactoring


Easily rename fields, methods, classes, interfaces, and packages, as well as add get/set
methods for fields.


Source
-
level debugging


Set absolute breakpoints (where execution stops at a line of code) or conditional
breakpoints (where execution stops when a condition is met).


Support for stepping into method calls as well as over them, jumping out of methods, and
"run to cursor," where the code executes until it reaches the selected line of code.


Visual code browsers like


“Project Explorer” that let you quickly locate classes, methods, and fields within a project
without scrolling through numerous source files.


“Hierarchy” view that shows class inheritance hierarchies.


and others.


And many more…

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

http://www.ddj.com/dept/java/184406194

Eclipse Web Tools Platform
(WTP)

Eclipse Web Tools
Platform
*


Initial version of Eclipse came with the JDT and the Plug
-
in Development
Environment (PDE). JDT supported J2SE development while PDE
supported Java
-
based Eclipse plug
-
in development.



WTP adds platform support for J2EE, by extending Eclipse along two
dimensions, namely execution environments and artifact types.



The execution environment dimension defines where code runs.


Out
-
of
-
the
-
box, Eclipse lets you develop Java main programs that run in a
command shell, applets that run in a Web browser, JUnit tests that run in a
JUnit runner, and ANT tasks that run in ANT.



WTP extends Eclipse by adding servers (both J2EE and database servers) as
new execution environments. In general, you need to install an execution
environment, configure it in Eclipse, and associate it with development
artifacts that you want to run in it.

*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.


Eclipse majors in Java source code as a primary development artifact. However other
artifacts, such as PDE plug
-
in manifests and Ant build scripts, are also supported.



WTP extends Eclipse with support for the large set of new artifact types encountered in
J2EE development. These include HTML, CSS, JavaScript, XHTML, JSP, XML, XSD,
WSDL, SQL, and all the J2EE 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.



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 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.

Eclipse WTP
-

J2EE Perspective

Eclipse WTP Key Features


Server tools


Let you define and control servers. Servers can be started, stopped, started in
debug mode, and controlled in other ways. Servers can be associated with
projects & projects can be deployed to servers.



WTP includes server support for Apache Tomcat, JBoss & many other popular
commercial and Open Source J2EE application servers.



The server tools include an extension point so that new server types can be easily
supported. Apache Geronimo is supported in this way.



Web tools


Let you create static Web pages based on HTML, XHTML, CSS, and JavaScript.



WTP Web editors provide content assist, syntax highlighting, validation, and
other standard Eclipse editor functions



The Web tools also include an embedded Web browser and a TCP/IP monitor
that's very handy for debugging HTTP traffic.

Eclipse WTP Key Features
(continued)


XML tools


Include source editors for XML, DTD, and XSD. Graphical editing is also
provided for XSD besides source editing.


Also include code generators for creating XML instance documents from
DTD or XSD.



Web Service tools
-

that include


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.

Eclipse WTP Key Features
(continued)


J2EE tools


Let you create J2EE projects and artifacts like JSPs, servlets, and
EJBs, as well as the J2EE deployment descriptors, and deploy these
to app servers.



The J2EE tools have a JSP source editor and a J2EE Project
Navigator that displays J2EE components as objects. This provides a
higher
-
level view of your project resources, for example, by
displaying all the files related to an EJB as a single EJB object.



Data tools


Include support for connecting to JDBC
-
based databases such as
Cloudscape, Derby, and other commercial and Open Source
databases, and exploring their tables.



The data tools also include an SQL source editor that lets you easily
execute SQL statements and view the results.

Geronimo Eclipse Plug
-
in

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

Hands
-
on Exercises

Hands
-
on Exercises


IDE Setup



Add Geronimo runtime into WTP


Start Geronimo server



Create a new Web application


Create a simple JSP


Deploy the Web application


Make changes to the Web application and redeploy



Undeploy Web application


Stop Geronimo server



Debug the Web application

IDE Setup


Download & Install Geronimo v1.1.1 from
http://geronimo.apache.org/downloads.html


“Geronimo 1.1.1 with Tomcat (zip)” is used in this presentation.



Download and install WTP v1.5.2 all
-
in
-
one
-
sdk from
http://download.eclipse.org/webtools/downloads/drops/R1.5/R
-
1.5.2
-
200610261841/


This includes Eclipse v3.2.1, WTP v1.5.2 and WTP’s pre
-
requisites namely
EMF, GEF & JEM.


“wtp
-
all
-
in
-
one
-
sdk
-
R
-
1.5.2
-
200610261841
-
win32.zip” is used in this
presentation.



Download and install Geronimo Eclipse Plug
-
in v1.2 as per the
instructions at
http://geronimo.apache.org/development
-
tools.html



Finally start eclipse with “
-
clean” option (i.e. “eclipse

clean”).


Switch to “J2EE” perspective.

Add Geronimo runtime into WTP

1.
Go to “Window
-
> Preferences
-
> Server
-
> Installed Runtimes”.


2.
Click on “Add” to add the installed Geronimo instance into the
WTP environment.


3.
In the “New Server Runtime” wizard, select “Apache
-
> Apache
Geronimo v1.1” and click “Next”.


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


5.
Click “Finish” to complete adding new server runtime. Click
“OK” to close “Preferences” dialog.

Step 3

Step 4

Add Geronimo runtime into WTP

Add Geronimo runtime into WTP

6.
Click on the “Servers” tab (bottom half of Eclipse window).


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

8.
“Apache Geronimo v1.1 Server” should already be selected as
the “server type” and the server runtime that you just created
should also be selected under “Server runtime”. Click Finish.

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 Status of your server now says “Started” as shown below:

Create a new Web application

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


2.
Expand “Web” and select “Dynamic
Web Project” as shown in fig. Click
“Next”.

3.
Enter “SimpleWeb” as the project name and make sure “Apache
Geronimo v1.1” 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”. (Note if you get a warning about caching a resource
copyrighted by Sun Microsystems click on “I Agree”).

Create a simple JSP

1.
From the “Project Explorer” view
expand the “SimpleWeb” project and
then select the “WebContent” folder.
Right click and select “New
-
>JSP”
from the context menu as shown

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. Note that the
State column now 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.

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.

Debug the web application

1.
Go back to the JSP Editor and replace the contents within <body> </body>
HTML tags as below:

<jsp:useBean id="datetime" class="java.util.Date" />

Hello UnderWorld.<br>

This application is being run on ${datetime}.


2.
Add a breakpoint at line 10 (line with <jsp:useBean ..> code)


3.
Type “Ctrl + S” to save the changes.


4.
From the “Project Explorer” view, select “index.jsp”. Right click on it and
select “Debug As
-
> Debug on Server”


5.
Accept the defaults in the “Debug on Server” dialog and click “Finish”.

Debug the web application

6.
The Geronimo server will now be started in Debug mode. As before the
web application will be deployed and run. Since we have put a breakpoint
in “index.jsp” the execution will now stop and IDE will ask for switching to
“Debug” perspective. Click “Yes” to switch to the “Debug” perspective.

Debug the web application

7.
We can now step through our JSP, viewing and changing variable values as
we go. When we continue execution (using the green arrow), the JSP is
served into the Web browser.


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


<jsp:useBean id="datetime" class="java.util.Date" />


9.
In the “Variables” view, scroll down and select “datetime” variable, expand
it and then select “fastTime”.


10.
Click in the “Value” column. You will see that the value of “datetime” can
now be changed. Change the first number from “1” to “2”. Click “Enter”


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


12.
In the browser you will observe that the value displayed for current date and
time is changed.

Hands
-
on Exercises


IDE Setup



Add Geronimo runtime into WTP


Start Geronimo server



Create a new Web application


Create a simple JSP


Deploy the Web application


Make changes to the Web application and redeploy



Undeploy Web application


Stop Geronimo server



Debug the Web application

Resources & References

Resources & References


ApacheCon Asia 2006 presentation by Rakesh Midha


“Inside Apache Geronimo 1.1
-

What makes it special?”


http://asia.apachecon.com/wp
-
content/presentations/ApacheCon2006.ppt



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

Resources & References


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/



IBM developerWorks article by author Lin Sun


“Using the Eclipse
Plug
-
in for WebSphere Application Server Community Edition”


http://www
-
128.ibm.com/developerworks/websphere/library/techarticles/0604_sun/0
604_sun.html

Q&A

Shiva Kumar H.R.

shivahr@gmail.com