Since I’d been using Eclipse for a while now, I decided to give the JBoss Tools 2.0.1.GA a spin, with a focus on using it with Tomcat 6 instead of JBoss AS. JBoss Tools is a set of plugins released by the JBoss team for rapid Seam application development. However, by default it supports development to the JBoss Application Server, although Seam applications can be deployed to most application servers.
I followed the instructions detailed in the new Chapter 3 of the Seam Reference Manual in Seam 2.0.2.GA, making sure that I rather specified my installed Tomcat 6 instead of JBAS and also specified a WAR instead of EAR structure. After the project structure is created, there are a few changes that need to be made to make things nice and easy.
To make sure that we all have the same view of the project structure, open the Seam perspective.
Tomcat enables us to put resources that are needed in each application (like datasources) in a META-INF/context.xml. Here is what mine looks like.
<?xml version="1.o" encoding="UTF-8"?>
<Context crossContext="true" debug="5" docBase="seamweb" path="/seamweb" reloadable="true">
<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" maxActive="20" maxIdle="10" maxWait="-1" name="jdbc/seamweb" password="" type="javax.sql.DataSource" url="jdbc:mysql://localhost:3306/seamweb" username="edem"/>
</Context>
In Eclipse, this file should go into the WebContent/META-INF folder.
Next is to work on the persitence.xml file which will be found under src/model/META-INF. Change the following line in that file which looks like this
<jta-data-source>java:/seamwebDatasource</jta-data-source
to this
<jta-data-source>java:comp/env/jdbc/seamweb</jta-data-source>
This is the standard way of declaring JNDI names, and Tomcat expects that. Also, change the “transaction-type” from “JTA” to “RESOURCE_LOCAL”.
Next thing to deal with is the components.xml file under WebContent/WEB-INF/. Remove the jndi-pattern = “@jndiPattern” attribute since we are not using EJBs here. Your file should now look like this.
<core:init debug="true"/>
<core:manager conversation-timeout="240000" concurrent-request-timeout="500" conversation-id-parameter="cid"/>
<transaction:entity-transaction entity-manager="#{entityManager}"/>
<persistence:entity-manager-factory name="seamweb"/>
<persistence:managed-persistence-context name="entityManager" auto-create="true" entity-manager-factory="#{seamweb}"/>
<security:identity authenticate-method="#{authenticator.authenticate}"/>
<event type="org.jboss.seam.notLoggedIn">
<action execute="#{redirect.captureCurrentView}"/>
</event>
<event type="org.jboss.seam.postAuthenticate">
<action execute="#{redirect.returnToCapturedView}"/>
</event>
Take note of “seamweb” declarations. Its the same as the persistence-unit name provided in the persitence.xml file.
Now delete the WebContent/WEB-INF/jboss-web.xml file. It’s definitely not necessary to tomcat.
The last but most important part of this exercise is making sure you have the right jar files in WEB/lib. After creating the project, JBoss Tools copies all the jar files from seam’s lib folder into your web application. The only way to know the jars needed for tomcat deployment only is to jpa example in seam distribution you have. Follow the instructions on my post about setting up NetBeans 6.0 for Tomcat 6 and you’ll see how i did it.
But to save you that trouble, this list of jars seem to work for me
-
antlr.jar
- asm.jar
-
cglib.jar
-
commons-beanutils.jar
-
common-collections.jar
-
commons-digester.jar
-
commons-lang.jar
-
commons-logging.jar
-
dom4j.jar
-
hibernate-annotations.jar
-
hibernate-commons-annotations.jar
-
hibernate-entitymanager.jar
-
hibernate.jar
-
hibernate-validator.jar
-
javassist.jar
-
jbos-archive-browsing.jar
-
jboss-el.jar
-
jboss-seam-debug.jar
-
jboss-seam.jar
-
jboss-seam-ui.jar
-
jsf-api.jar
-
jsf-facelets.jar
-
jsf-impl.jar
-
jstl.jar
-
jta.jar
-
persistence-api.jar
-
richfaces-api.jar
-
richfaces-impl.jar
-
richfaces-ui.jar
If everything went well, the application should run inside tomcat without a problem.

Posted by Edem Morny