Creating a Seam project with eclipse and deploying it on tomcat tutorial
What i’m about to show you is not really much of a tutorial but more of an example of one way of working with eclipse and deploying your seam based web app to tomcat. If you’re ok with JBoss, then go with it, nothing beats the support and ease of configuration that the JBoss AS provides for deploying seam applications. But since I was running JBoss on an old 5400 rpm hard disk with 25 other applications reading and writing data to it, it used to take 10+ minutes for it to startup (7m with reduced logging) and anywhere from 4 to 10 minutes for a hot redeploy of the application. Maybe I wasn’t doing it right but I decided to switch to tomcat for it’s ease of use and because i’m more familiar with its errors and pitfalls (configuring a ds comes to mind).
There are a few good tutorials out there if you want to work with JBoss and maybe one or two good ones for tomcat but nothing that works out of the box. One special tutorial is a screencast with lots of good screenshots but it’s kinda redundant now because JBoss tools have evolved over time.
I worked with all those tutorials for a couple of days and then decided to go back to the basics. First, what you must absolutely have on your machine:
- Latest seam download
- Latest Tomcat
- Latest eclipse with JBoss tools installed
I’m not going to do any fancy stuff in this example, just create a seam eclipse project and then deploy it to tomcat. Once you have JBoss tools installed, right click and create a new project. You’ll see seam related options in the window :

Create a new project and give it a name. If you haven’t already, add the tomcat runtime. In the configuration section choose your version of seam. I don’t know what impact this particular choice has but I figured it’s safe to go with the version you have.
At this point, you can click finish and be done with it. But if you want to configure more settings, go ahead and click Next to see whats available although you can do all of that in your config files manually as well.
Once the project is created, the first thing to do is have tomcat supply us a connection. The easiest way to do this is to create a file named context.xml in your WebContent/META-INF folder and create a new resource there. My sample file looked something like:
<Context path="/seamtom" docBase="seamtom" debug="5" reloadable="true" crossContext="true"> <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="erc" password = "erc" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/erc"/> </Context>
The next thing to do is modify the config files that use this connection. Open up persistence.xml and change the jta-data-source value from whats written there to java:comp/env/jdbc/TestDB. This is because tomcat by default prefixes all connections with java:comp/evn.
The last thing to do is go into your component.xml and add the following line :
<transaction:entity-transaction entity-manager="#{entityManager}"/>
I just want to point out that you don’t need to do any fancy editing of files here. Just the three changes will do:
- Create a tomcat-managed datasource
- Change the name of the datasource in the persistence.xml
- Add the transaction manager in the components.xml.
Thats it.
No related posts.

Nice, it works and i am happy for it. one question – when i try to create spring bean i got this error : Cannot find class [cz.recepce.session.PersonSpringBean] for bean with name ‘personSpringBean’ defined in ServletContext resource [/WEB-INF/applicationContext.xml]
so how is possible that spring cant see my class ? i have it in the same package like seam POJOs which works fine …
Are you sure the class name is correct? Also are you sure the class ie being compiled?
Hi, problem was in ‘src/hot’ directory, classes in this directory has been ignored so i am using now just ‘src’ directory (i had to replace all occurs of ‘src/hot’ in some hidden *.prefs files). Could you send me /or public/ your sample project ? I still wonder what was wrong with mine project… Thank you, have a nice day.