Archive for the ‘Jboss Seam’ Category

Seam development with Eclipse and Tomcat Step-by-Step

Tuesday, October 26th, 2010

RAD: Seam development with Eclipse and Tomcat Step-by-Step-Tutorial Screencast

Posted by: techiexchange on: November 11, 2007


Jboss Seam
, one of the most innovative full-stack web application framework in Java EE era.

Letz dive in to the tutorial directly without explaining more about Seam.

In order to develop an enterprise application, one must have
an application server installed locally, which is a big pain
when considering system resource and performance. During the
development period developer always perfer to have his
code-hotdeploy time as short as possible, which rapidly
increases his development and production. But this is not
easily achieved when application servers are used during
development. An alternative is to use web servers which are
very light when compared to Application servers. Seam has a
good support for Tomcat webserver.

This tutorial focuses Seam development under Tomcat webserver without support for EJB, that means Seam with POJO and JPA+Hibernate as Persistence provider.

Main goal of this tutorial is to achieve RAD-Rapid Application Development with Seam, Tomcat and Eclipse.

Requirements for Seam development envirnoment:

Download latest Seam release

Download Tomcat 5.5
or Tomcat 6
Download latest Eclipse

Download Eclipse-Tomcat-Sysdeo plugin

This is a screencast (static) showing all the screenshots without explanation.

Here we go….

Extract Seam 2 GA distribution on local hard disk (see Figure 1)


Download JBoss Seam and extract

JPA example from Seam 2 GA distribution (see Figure 2)


2-seam-jpa-example.png

Build JPA example for Tomcat 5.5 by using ant (make sure that ANT already installed) command:ant tomcat55

Building JPA WAR file (see Figure 3)


3-build-jpa-example-tomcat.png

Once build successfull, then you can find the war file inside dist-tomcat55 folder (see Figure 4)


4-build-jar-jpa-example.png

Now import WAR file to Eclipse to make an Eclipse project (see Figure 5)


5-eclipse-import-example.png

In order to import WAR file select Web -> WAR file from Eclipse import console (see Figure 6)


6-eclipse-import-war.png

Choose absolute path of jboss-seam-jpa.war file and press next (see Figure 7)


9-eclipse-import-jpa-war.png

Import all libs from WEB-INF/lib (don’t select any libs) (see Figure 8)


10-eclipse-import-war-default-lib.png

Here’s new project created in Eclipse workspace (see Figure 9)


11-eclipse-project-hierarchy.png

Create classes inside WEB-INF to build src files (see Figure 10)


12-eclipse-create-classes-folder.png

Configure the build path so that src folder takes correct classes folder (see Figure 11)


13-project-class-folder.png

Choose classes folder as default output folder (see Figure 12)


14-select-class-folder.png

Copy src from Seam-JPA example (see Figure 13)


15-copy-src-from-example.png

Paste into the src folder in Eclipse (see Figure 14)


16-paste-src-from-example.png

Now src are shown in the hierarchy but with errors (see Figure 15)


17-project-jpa-src.png

Delete ImportedClasses folder in root of Project workspace (see Figure 16)


18-delete-importedclasses-folder.png

In order to remove src errors in the project import TestNG lib to WEB-INF/lib (see Figure 17)


19-import-testng-jar.png

Now Project src has been done without any errors (see Figure 18)


20-project-no-errors.png

Configure Tomcat Sysdeo plugin to installed home directory of Tomcat (see Figure 19)


7-eclipse-sysdeo-tomcat-configuration.png

See Eclipse toolbar for Sysdeo-Tomcat shortcuts – Start, Shutdown, Restart (see Figure 20)


8-eclipse-sysdeo-tomcat-installed.png

Tell the created Project (jboss-seam-jpa) that it is a web project to Sysdeo plugin (Project ->rightclick-Properties-> Tomcat) (see Figure 21)


21-project-as-tomcat-web-project.png

Now update/define about project’s context in Tomcat (server.xml will be updated) (see Figure 22)


22-update-context-tomcat.png

Open context.xml (inside Webcontent/META-INF) and copy Resource tag (see Figure 23)


23-copy-context-defn.png

Goto server.xml (Tomcat_Home/conf) and see whether project context is defined (see Figure 24)


24-server-xml-context-before.png

Paste Resource tag (make sure that Resource is closed properly) copied from context.xml as child tage to Context tag in server.xml (see Figure 25)


25-server-xml-context-after.png

In order to work with HSQL DB, copy hsql.jar from Seam distribution to Tomcat-Home/common/lib folder (see Figure 26)


26-paste-hsql-lib-in-tomcat.png

Now all configuration things are over, so Start Tomcat inside Eclipse by pressing Start icon on Eclipse-Sysdeo toolbar (see Figure 27)


27-start-tomcat-sysdeo.png

You can see the console output of Tomcat saying server started (see Figure 28)


28-tomcat-started.png

Test whether the application started without any errors by opeing a browser and navigating

http://localhost:tomcatport/jboss-seam-jpa

Note that the footer of the front page. We’re going to change that in the next step. (see Figure 29)


29-test-example-browser1.png

Open home.xhtml (front page of the application) located inside WebContent and check the footer (see Figure 30)


30-home-xhtml-src-before.png

Edit footer note and save the page (see Figure 31)


31-edit-home-xhtml-page.png

Now goto opened browser where application is already running, and press Refresh or F5 to reload the page.
That’s it.. without starting the server your code got hot deployed and web page was reloaded. (see Figure 32)


32-refresh-web-page.png

Please note that Tomcat should be used only during development phase in order to increase the development productivity, use some application server to deploy production applications.

I hope this tutorial gives a kick-off project template for Seam with POJO+JPA+Hibernate based application.

Share your thoughts.