Tweaking JBoss Tools and Eclipse for Tomcat 6

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

  1. antlr.jar

  2. asm.jar
  3. cglib.jar

  4. commons-beanutils.jar

  5. common-collections.jar

  6. commons-digester.jar

  7. commons-lang.jar

  8. commons-logging.jar

  9. dom4j.jar

  10. hibernate-annotations.jar

  11. hibernate-commons-annotations.jar

  12. hibernate-entitymanager.jar

  13. hibernate.jar

  14. hibernate-validator.jar

  15. javassist.jar

  16. jbos-archive-browsing.jar

  17. jboss-el.jar

  18. jboss-seam-debug.jar

  19. jboss-seam.jar

  20. jboss-seam-ui.jar

  21. jsf-api.jar

  22. jsf-facelets.jar

  23. jsf-impl.jar

  24. jstl.jar

  25. jta.jar

  26. persistence-api.jar

  27. richfaces-api.jar

  28. richfaces-impl.jar

  29. richfaces-ui.jar

If everything went well, the application should run inside tomcat without a problem.

Advertisements

19 thoughts on “Tweaking JBoss Tools and Eclipse for Tomcat 6

  1. After such setup I have java.lang.ClassNotFoundException: org.jboss.embedded.tomcat.EmbeddedJBossBootstrapListener

    It’s seems to me that it’s needed to install EmbeddedJBoss to tomcat

  2. This post assumes Seam development with POJOs and JPA on Tomcat 6,0, without the use of EmbeddedJBoss. I believe you are using EmbeddedJBoss, which is causing your exception. Check the seam forums for help on this.

  3. Yes. you’re right. I had some parameters for jboss embedded in my server.xml without libs for it. Thank’s for answer

  4. Pingback: Bookmarks about Eclipse

  5. After such setup I have a

    SEVERE: Exception sending context initialized event to listener instance of class org.jboss.seam.servlet.SeamListener
    org.jboss.seam.InstantiationException: Could not instantiate Seam component: LearningSEAMByExampleEntityManagerFactory
    at org.jboss.seam.Component.newInstance(Component.java:2106)
    at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304)
    at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278)
    at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:112)
    at org.jboss.seam.init.Initialization.init(Initialization.java:735)
    at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:35)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:627)
    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:516)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
    Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named LearningSEAMByExample
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:89)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
    at org.jboss.seam.persistence.EntityManagerFactory.createEntityManagerFactory(EntityManagerFactory.java:81)
    at org.jboss.seam.persistence.EntityManagerFactory.startup(EntityManagerFactory.java:50)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
    at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
    at org.jboss.seam.Component.callComponentMethod(Component.java:2219)
    at org.jboss.seam.Component.callCreateMethod(Component.java:2134)
    at org.jboss.seam.Component.newInstance(Component.java:2094)
    … 29 more

    I used Seam-gen to create my project and I add persistence.xml in MEAT-INF under source folder.

    This is my components.xml file:

    *.seam

    /security.drl

    And this is my persistence.xml file :

    org.hibernate.ejb.HibernatePersistence
    java:comp/env/jdbc/LearningSEAMByExample

    Could you help me ?

  6. Hello, I have done all the steps, but it still doesn’t work.

    I use Eclipse 3.4, apache-tomcat-6.0.18 and jboss-seam-2.1.2.CR1.

    Wen I start tomcat, I have this warning:

    ADVERTENCIA: Unable to process deployment descriptor for context ‘/tomcatDemo’

    then I have:

    Estado HTTP 404 – /tomcatDemo/

    could you help me?

    Thanks

  7. Hello Edem

    I followed your guide accurately but I’m getting the following exception during the tomcat startup:

    SEVERE: Exception sending context initialized event to listener instance of class org.jboss.seam.servlet.SeamListener
    org.jboss.seam.InstantiationException: Could not instantiate Seam component: tpjtEntityManagerFactory
    at org.jboss.seam.Component.newInstance(Component.java:2096)
    at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304)
    at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278)
    at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:112)
    at org.jboss.seam.init.Initialization.init(Initialization.java:727)
    at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:34)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:516)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
    Caused by: javax.persistence.PersistenceException: org.hibernate.HibernateException: Could not locate TransactionManager
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:737)
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
    at org.jboss.seam.persistence.EntityManagerFactory.createEntityManagerFactory(EntityManagerFactory.java:81)
    at org.jboss.seam.persistence.EntityManagerFactory.startup(EntityManagerFactory.java:50)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
    at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:138)
    at org.jboss.seam.Component.callComponentMethod(Component.java:2209)
    at org.jboss.seam.Component.callCreateMethod(Component.java:2124)
    at org.jboss.seam.Component.newInstance(Component.java:2084)
    … 20 more
    Caused by: org.hibernate.HibernateException: Could not locate TransactionManager
    at org.hibernate.transaction.JNDITransactionManagerLookup.getTransactionManager(JNDITransactionManagerLookup.java:26)
    at org.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:325)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
    at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:730)
    … 34 more
    Caused by: javax.naming.NameNotFoundException: Name TransactionManager is not bound in this Context
    at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
    at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
    at org.apache.naming.SelectorContext.lookup(SelectorContext.java:137)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at org.hibernate.transaction.JNDITransactionManagerLookup.getTransactionManager(JNDITransactionManagerLookup.java:23)
    … 38 more

    Any ideas about what might be the reason?

    I’m using eclipse 3.4, tomcat 6.0.18 and seam-2.1.0.SP1

    Thanks in advance.

    • @dmitry: Check out for two things in your persistence.xml

      transaction-type=”RESOURCE_LOCAL” and not “JTA”
      That you don’t have added any property specifying transaction manager etc. because that’s where ur bug is coming from

  8. Thanks for your quick response Edem. Here is my persistence.xml file. It’s almost the same as it was after jboss-tools generated it.

    org.hibernate.ejb.HibernatePersistence
    java:comp/env/tomcatseampjtDatasource

  9. persistence xmlns=”http://java.sun.com/xml/ns/persistence”
    xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
    xsi:schemaLocation=”http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
    version=”1.0″

    persistence-unit name=”tomcatseampjt” transaction-type=”RESOURCE_LOCAL”
    provider org.hibernate.ejb.HibernatePersistence
    jta-data-source java:comp/env/tomcatseampjtDatasource
    properties
    hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
    hibernate.hbm2ddl.auto = update
    hibernate.show_sql = true
    hibernate.format_sql = true
    hibernate.transaction.manager_lookup_class = org.hibernate.transaction.JBossTransactionManagerLookup
    /properties
    persistence-unit
    persistence

    • Like I said before, you do have a transaction manager lookup configured in your file. This is automatically put in by jboss-tools even though u didn’t specify any such thing.
      i.e.
      hibernate.transaction.manager_lookup_class = org.hibernate.transaction.JBossTransactionManagerLookup

      If you are not using the JBossTransactionManagerLookup, then remove this property declaration.

  10. Great job. This was excatly the same kind of tutorial I was thinking to do.

    You seemed to leave out some minor details, such as the log4j.xml (and .dtd) is missing by default (should be eg. in src/main)

    And from persistence.xml surely this JB related transaction manager can be commented out (At least I’ve got error with it)..

    property name=”hibernate.transaction.manager_lookup_class” value=”org.hibernate.transaction.JBossTransactionManagerLookup”

    I also used non-jta-data-source -tags instead of jta-data-source in datasource declaration in persistence.xml. With my configuration I had some JTA-related errors before I changed it. My DS was propably not compatible with JTA.

    Good work anyway. I think you should post this tutorial also in seamframework discussion forum.

    • @Harri: Actually it is already on seamframework, related to blog posts or something of sorts 🙂 .Thanks very much anyway.

  11. Edem,
    Have you ever tried to setup datasource on server and have it configured as a link on context.xml? It has the advantage of completely decoupling environment configuration from your binaries (ie.: same binary can go to test, qa, live without changes).
    You only need to specify as follows on context.xml:

    Then have this on server.xml under GlobalNamingResources:

    And your app would look the connection under java:comp/env/jdbc/myDSOnMyApp

    regards,
    Rafael Ribeiro

    • Yes Rafael, I have. However, I was working with the assumption that I may have to deploy this to a shared hosting provider, which will not give me access to the global tomcat context.xml. Thanks for that addition.

  12. Hello,
    I have a warn :
    log4j:WARN No appenders could be found for logger (org.ajax4jsf.renderkit.ChameleonRenderKitFactory).
    log4j:WARN Please initialize the log4j system properly.

    It’s probably due to the absence of log4j.xml or log4j.properties. I’ve tried to make a log4j.properties from elsewhere on the web. I’ve tried to put it in different places in my project but the warn still remains.

    I also have an error (in French) :
    GRAVE: Exception lors de l’envoi de l’évènement contexte initialisé (context initialized) à l’instance de classe d’écoute (listener) org.jboss.seam.servlet.SeamListener
    org.jboss.seam.InstantiationException: Could not instantiate Seam component: entityManagerFactory

    Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named seamtomcat

    And after hours of research on the web, I still don’t know how to fix it !

    My environment :
    Eclipse Galileo 3.5.2
    JBoss Tools 3.1
    JBoss Seam 2.2.0 GA
    Tomcat 6.0.29

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s