Help

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

The recommended approach for running a Seam application on Apache Tomcat is to infuse Tomcat with the Embedded JBoss distribution. This turns JBoss AS inside out, making Tomcat the outer web container and JBoss AS the nested Java EE container. Naturally, you would expect an application that runs on JBoss AS to also run on this hybrid container. However, you may need to run a Seam application on a vanilla Tomcat installation. It turns that this configuration is not that difficult to setup. In this article, we'll be taking a normal seam-gen project and deploying it to Tomcat after performing some modifications.

There are three obstacles we need to overcome to deploy a Seam project to vanilla Tomcat. The first is the JDBC data source, the second is transactions, and the third is library dependencies. Let's begin with the data source.

Setting up a JDBC data source

The typical peristence configuration in a Seam application assumes that the application server will manage the JDBC connection and make it available through JNDI. Although there's no UI to configure it, Tomcat can satisify this contract. The JDBC data source is configured as a Tomcat resource. Although a shared configuration is possible, you have the option of embedding the data source configuration inside the application. That's the approach we'll take here for portability.

Create the file tomcat-context-dev.xml in the resources folder and add an empty <Context> element.

<?xml version="1.0" encoding="UTF-8"?>
<Context>
</Context>

Next set the context path of the application, which in our example is /vehicles:

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/vehicles">
</Context>

Finally, add the following resource definition, using the proper credentials and JDBC driver for your application's database. Some sensible defaults are shown here.

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/projectName">
   <Resource auth="Container"
      name="vehiclesDatasource"
      type="javax.sql.DataSource"
      driverClassName="com.mysql.jdbc.Driver"
      url="jdbc:mysql://localhost/projectName"
      username="user"
      password="secret"
      maxActive="100"
      maxIdle="30"
      maxWait="10000"/>
</Context>

Now let's get the build to put this file in the right place. It needs to end up as META-INF/context.xml in the root of the WAR. Add the following command to the end of the war target in the build.xml file:

<copy file="${basedir}/resources/tomcat-context-${profile}.xml"
   tofile="${war.dir}/META-INF/context.xml"/>

Next, you need to get your persistence unit configuration (i.e., META/persistence.xml) to reference this resource in JNDI. Tomcat binds resources to the java:comp/env JNDI namespace, so the value of the name attribute in the resource is appended to this namespace. We also need to use a non-JTA datasource, which I'll explain later.

Open up the resources/persistence-dev.xml file and make the following changes:

  1. Remove the transaction-type attribute
  2. Remove the <jta-data-source> element
  3. Remove the hibernate.transaction.manager_lookup_class <property> element
  4. Add a <non-jta-data-source> element that matches the name of the JDBC resource you configured above

The top part of the descriptor should match the exerpt below:

<?xml version="1.0" encoding="UTF-8"?>
<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="projectName">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <non-jta-data-source>java:comp/env/projectNameDatasource</non-jta-data-source>
      ...
   </persistence-unit>
</persistence>

The persistence unit configuration hinted at our transaction obstacle. Without significant research and trial and error, Tomcat does not support JTA. Fortunately, all JPA providers are capable of managing transactions using the transaction exposed by the database connection. This type of transaction is called a resource-local transaction. Seam's transaction management can be configured to use the resource-local transaction rather than JTA. Keep in mind, though, that you lose the ability to control transactions across multiple resources. But that is one of the prices you pay for using Tomcat.

Switching to resource location transactions

The first step is to inform the persistence unit to create persistence contexts that manage their own transactions, which we have already done. The second step is to tell Seam to use the persistence context's transaction, or entity transaction. To make this switch, register the org.jboss.seam.transaction.entityTransaction component in the Seam compoennt descriptor. This requires importing the appropriate namespace:

<?xml version="1.0" encoding="UTF-8"?>
<components xmlns="http://jboss.com/products/seam/components"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   ...
   xmlns:tx="http://jboss.com/products/seam/transaction"
   xsi:schemaLocation="
      ...
      http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.1.xsd
      http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd">
   ...
   <tx:entity-transaction/>
</components>

There's only one step left, the libraries.

Adding the extra libraries

You need to package Hibernate and it's dependencies, as well as some core Java EE APIs since these things are not provided by Tomcat out of the box. Open up the deployed-jars.list file in the root of the project and add the following lines:

# JPA and Hibernate
commons-logging.jar
commons-collections.jar
cglib.jar
antlr.jar
asm*jar
log4j.jar
dom4j.jar
javassist.jar
hibernate.jar
hibernate-annotations.jar
hibernate-commons-annotations.jar
hibernate-entitymanager.jar
hibernate-validator.jar
jboss-common-core.jar
persistence-api.jar
# JSF
jsf-api.jar
jsf-impl.jar
# JTA
jta.jar
# JSTL
jstl.jar

The project is ready! Now you just need to create the archive and copy it to the Tomcat deployment directory. First, build the archive.

ant archive

Then copy dist/projectName.war to the $TOMCAT_HOME/webapps directory. If you want to use an exploded archive, begin by staging the archive:

ant stage

Then copy the exploded-archives/vehicles.war directory to $TOMCAT_HOME/webapps/vehicles.

Now you have a seam-gen project running on a vanilla Tomcat installation!

A note about logging

One of the main differences between Tomcat and JBoss AS that many people struggle with is how logging is handled, specifically commons-logging. In Tomcat, logging can be configured from within the application, thus allowing you to have different appenders and log levels per application. JBoss AS centralized logging so you only need a single log configuration file.

When deploying to JBoss AS or Tomcat with Embedded JBoss, you configure all logging in one place. Deploying a Seam application to Tomcat without Embedded JBoss works just like any other WAR file deployed to Tomcat. So you simply add log4j.xml (or log4j.properties) to your classpath (WEB-INF/classes) and you can configure logging however you please!

14 comments:
 
29. May 2009, 20:03 America/New_York | Link
Chris Hoffman
This looks very helpful! However, I could use a little more information. For example, are these steps to be done after running 'seam setup', or after 'seam create-project'? Where are some of the files referred to above (e.g., the seam component descriptor -- is it in the project, in the seam-gen subdirectory, or elsewhere)?
Thanks!
 
08. Jun 2009, 13:22 America/New_York | Link

For Tomcat 5.5, the following libraries aren't provided in the Tomcat runtime and need to be added to deployed-jars.list:

  • el-api.jar
  • el-ri.jar

@Chris, the steps need to be completed after you've create the project (i.e. after 'ant create-project'). The component descriptor is components.xml in the resources/WEB-INF folder of the new project,

 
31. Jul 2009, 09:43 America/New_York | Link
Seam 2.2.0.GA / Tomcat 6.0.20 User

I replicate this procedure verbatim with Seam 2.2.0.GA and Tomcat 6.0.20 but when I go to http://localhost:8080/mysite/ I get:

The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

Same issue on Safari. Can somebody please verify the procedure works with the Seam 2.2.0.GA. I know it was just GA'd yesterday. This procedure is very straight forward so I have not a clue why I am having an encountering this issue. I can run the jboss-seam-jpa example without a problem so perhaps it is something I am doing.

 
04. Aug 2009, 06:42 America/New_York | Link
Seam 2.2.0.GA / Tomcat 6.0.20 User

Ok I finally was able to get it to work. I had to remove the debug attribute from

<core:init />

in components.xml and I had to remove the catch all in pages.xml:

    <exception>
        <redirect view-id="/error.xhtml">
            <message severity="error">Unexpected error, please try again</message>
        </redirect>
    </exception>

What's up with this? Also what is up with the lack of support on this portal? Do we have to bread to get some help. So much for an open-source community! Other than that Seam ROCKS! Congrats on JSR-299. Keep this train moving. Peace.

 
17. Aug 2009, 23:25 America/New_York | Link

I think I've followed all the steps above but I haven't quite gotten Tomcat (v5.5.28 - a fresh install and Seam 2.2.0-GA) to run my app yet. When I try to start the app (http://localhost:8080/pctkms), I get the following error in the Tomcat catalina log:

Aug 17, 2009 5:10:15 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive pctkms.war
Aug 17, 2009 5:10:35 PM com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Mojarra (1.2_12-b01-FCS) for context 'null'
Aug 17, 2009 5:10:39 PM com.sun.faces.spi.InjectionProviderFactory createInstance
INFO: JSF1048: PostConstruct/PreDestroy annotations present.  ManagedBeans methods marked with these annotations will have said annotations processed.
Aug 17, 2009 5:10:40 PM com.sun.faces.config.ConfigureListener installExpressionFactory
SEVERE: Unable to instantiate ExpressionFactory 'com.sun.el.ExpressionFactoryImpl'
Aug 17, 2009 5:10:40 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
Aug 17, 2009 5:10:40 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/pctkms] startup failed due to previous errors
Aug 17, 2009 5:11:30 PM com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Mojarra (1.2_12-b01-FCS) for context 'null'
Aug 17, 2009 5:11:33 PM com.sun.faces.spi.InjectionProviderFactory createInstance
INFO: JSF1048: PostConstruct/PreDestroy annotations present.  ManagedBeans methods marked with these annotations will have said annotations processed.
Aug 17, 2009 5:11:34 PM com.sun.faces.config.ConfigureListener installExpressionFactory
SEVERE: Unable to instantiate ExpressionFactory 'com.sun.el.ExpressionFactoryImpl'
Aug 17, 2009 5:11:34 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
Aug 17, 2009 5:11:34 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/pctkms] startup failed due to previous errors

Any ideas? I'd prefer to use JBoss instead of Tomcat (mostly because it seems to work with JBoss) but Tomcat is all my client allows.

Thanks!

 
18. Aug 2009, 22:35 America/New_York | Link

Hello,

I followed the instructions above: modified components.xml, persistence.xml, build.xml and added additional libraries. I had to comment out the catch-all exception in pages.xml as suggested above and updated the core-init element in components.xml to the following: <core:init debug="false" jndi-pattern="SecuredLogViewer/#{ejbName}/local" />.

I'm able to start the application but upon authenticating I encountering an exception "org.jboss.seam.InstantiationException: Could not instantiate Seam component: clientInfoList" Caused by: "java.lang.RuntimeException: exception invoking: getTransaction" caused by "javax.naming.NamingException: Cannot create resource instance" exception (full stack trace below).

Note: I tested my JNDI setup on a separate web app with context.xml and web.xml and it worked. I tried adding the <resource-ref>...</resource-ref> to my web.xml too but still get the same error.

I would very much appreciate any help... Thanks in advance!

org.jboss.seam.InstantiationException: Could not instantiate Seam component: clientInfoList
        at org.jboss.seam.Component.newInstance(Component.java:2106)
        at org.jboss.seam.Component.getInstance(Component.java:1988)
        at org.jboss.seam.Component.getInstance(Component.java:1950)
        at org.jboss.seam.Component.getInstance(Component.java:1944)
        at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:55)
        at org.jboss.seam.Namespace.getComponentInstance(Namespace.java:50)
        at org.jboss.seam.el.SeamELResolver.resolveBase(SeamELResolver.java:166)
        at org.jboss.seam.el.SeamELResolver.getValue(SeamELResolver.java:53)
        at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
        at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
        at org.jboss.el.parser.AstIdentifier.getValue(AstIdentifier.java:44)
        at org.jboss.el.parser.AstValue.getValue(AstValue.java:63)
        at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
        at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
        at javax.faces.component.UIOutput.getValue(UIOutput.java:184)
        at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:201)
        at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:284)
        at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:154)
        at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861)
        at org.jboss.seam.ui.util.cdk.RendererBase.renderChild(RendererBase.java:190)
        at org.jboss.seam.ui.util.cdk.RendererBase.renderChildren(RendererBase.java:166)
        at org.jboss.seam.ui.renderkit.DecorateRendererBase.doEncodeChildren(DecorateRendererBase.java:146)
        at org.jboss.seam.ui.util.cdk.RendererBase.encodeChildren(RendererBase.java:92)
        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
        at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:282)
        at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
        at org.richfaces.renderkit.html.SimpleToggleControlTemplate.doEncodeChildren(SimpleToggleControlTemplate.java:347)
        at org.richfaces.renderkit.html.SimpleToggleControlTemplate.doEncodeChildren(SimpleToggleControlTemplate.java:342)
        at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:121)
        at org.richfaces.renderkit.html.SimpleTogglePanelRenderer.encodeChildren(SimpleTogglePanelRenderer.java:208)
        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:936)
        at javax.faces.render.Renderer.encodeChildren(Renderer.java:148)
        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:936)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:942)
        at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
        at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
        at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:196)
        at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:109)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
        at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
        at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
        at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
        at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
        at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
        at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
        at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
        at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
        at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
        at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:177)
        at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
        at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)
        at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:507)
        at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
        at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
        at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
        at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
        at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.RuntimeException: exception invoking: getTransaction
        at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:154)
        at org.jboss.seam.Component.callComponentMethod(Component.java:2211)
        at org.jboss.seam.Component.unwrap(Component.java:2237)
        at org.jboss.seam.Component.getInstance(Component.java:2004)
        at org.jboss.seam.Component.getInstance(Component.java:1967)
        at org.jboss.seam.Component.getInstance(Component.java:1961)
        at org.jboss.seam.Component.getInstance(Component.java:1934)
        at org.jboss.seam.Component.getInstance(Component.java:1929)
        at org.jboss.seam.transaction.Transaction.instance(Transaction.java:36)
        at org.jboss.seam.util.Work.workInTransaction(Work.java:32)
        at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:89)
        at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
        at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
        at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
        at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
        at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
        at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
        at com.west.wic.session.ClientInfoList_$$_javassist_1.validate(ClientInfoList_$$_javassist_1.java)
        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:585)
        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:2211)
        at org.jboss.seam.Component.callCreateMethod(Component.java:2134)
        at org.jboss.seam.Component.newInstance(Component.java:2094)
        ... 75 more
Caused by: javax.naming.NamingException: Cannot create resource instance
        at org.apache.naming.factory.TransactionFactory.getObjectInstance(TransactionFactory.java:113)
        at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:793)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
        at org.apache.naming.SelectorContext.lookup(SelectorContext.java:137)
        at javax.naming.InitialContext.lookup(InitialContext.java:351)
        at org.jboss.seam.transaction.Transaction.getUserTransaction(Transaction.java:79)
        at org.jboss.seam.transaction.Transaction.createUTTransaction(Transaction.java:71)
        at org.jboss.seam.transaction.Transaction.getTransaction(Transaction.java:44)
        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:585)
        at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
        at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
        ... 101 more
 
09. Dec 2009, 15:42 America/New_York | Link

For me it was also necessary to put file jboss-el.jar from Seam distribution to commons/lib (Tomcat 5.5) or lib (Tomcat 6) (adding this file to application's lib directory doesn't work) to get application working. Otherwise the exception:

com.sun.faces.config.ConfigurationException: It appears the JSP version of the container is older than 2.1 and unable to locate the EL RI expression factory, com.sun.el.ExpressionFactoryImpl. If not using JSP or the EL RI, make sure the context initialization parameter, com.sun.faces.expressionFactory, is properly set.

Appeared.

 
18. Dec 2009, 03:05 America/New_York | Link
I was getting the JSP version error you indicated. However, copying the jboss-el to the tomcat/lib still did not fix the problem. Any thoughts?

Thanks ...
 
25. Dec 2009, 21:43 America/New_York | Link

Hello, Donald. Sorry for answering so late, I noticed I still have this entry in web.xml:

<context-param>  
     <param-name>com.sun.faces.expressionFactory</param-name>  
     <param-value>org.jboss.el.ExpressionFactoryImpl</param-value>  
</context-param>

I thought I removed it and it still works well therefore I didn't put it in my previous post. But now I realised this code is still in my applications web.xml. Sorry for confusion. I hope it will work for you now :).

 
01. Jan 2010, 11:45 America/New_York | Link

I deployed my app (tomcat6,mysql5,seam 2.1, JPA/Hibernate 3.1) using the approach described above. My current issue is I can use entityManager(extends from EntityHome) to query the result, but I cannot use entityManager to persist the object.

Who can help me? What I missed?

 
15. Mar 2010, 23:37 America/New_York | Link
I did a simple seam application with Tomcat 6.0.26, Seam 2.2.0.GA and Firebird 2.1

1. Create seam application targetting Tomcat 6

2. Copy jars to <tomcat>/lib
 jsf-api.jar
 jsf-impl.jar
 jsf-facelets.jar
 antlr.jar
 cglib-nodep.jar
 commons-logging.jar
 commons-collections.jar
 dom4j.jar
 javassist.jar
 jta.jar
 log4j.jar
 hibernate-annotations.jar
 hibernate-core.jar
 hibernate-commons-annotations.jar
 hibernate-entitymanager.jar
 hibernate-validator.jar
 persistence-api.jar
 slf4j-api.jar
 slf4j-log4j12.jar

3. Modify persistence.xml and components.xml
4. Add context.xml
5. "Seam Generate Entities"
6. Run.

Sometimes I get a concurrent exception.

By the way, with debug="false" the application doesnt shows any data.

Regards.
 
21. Mar 2010, 00:22 America/New_York | Link
Igor Lucas

I was able to successfully run my application in Tomcat without Embedded JBoss, using Tomcat 6.0.26 and Seam 2.2.0. Here are the steps:

1) Build a WAR archive based on your EAR file, with a structure like that:

MyProject.war/
MyProject.war/**/*.xhtml (jsp, html, gif, ...)
MyProject.war/META-INF/context.xml (step 2)
MyProject.war/WEB-INF/components.xml (step 3)
MyProject.war/WEB-INF/faces-config.xml
MyProject.war/WEB-INF/pages.xml
MyProject.war/WEB-INF/web.xml
MyProject.war/WEB-INF/classes/log4j.properties (step 4)
MyProject.war/WEB-INF/lib/MyProject.jar
MyProject.war/WEB-INF/lib/MyProject.jar/**/*.class (xml, properties, ...)
MyProject.war/WEB-INF/lib/MyProject.jar/META-INF/persistence.xml (step 5)
MyProject.war/WEB-INF/lib/*.jar (step 6)

2) Define a JDBC connection resource in context.xml:

<Context path="/MyProject">
   <Resource auth="Container"
      name="MyProjectDatasource"
      type="javax.sql.DataSource"
      driverClassName="com.mysql.jdbc.Driver"
      url="jdbc:mysql://localhost:3306/MyProject"
      username="MyUser"
      password="MyPassword"
      maxActive="100"
      maxIdle="30"
      maxWait="10000"/>
</Context>

Note: don't forget to put your JDBC driver in Tomcat/lib folder.

3) Change transaction and persistence configuration in components.xml:

From this:

  <persistence:managed-persistence-context 
               name="entityManager" 
               auto-create="true"
               persistence-unit-jndi-name="java:/MyProjectEntityManagerFactory"/>

To:

  <transaction:entity-transaction 
               entity-manager="#{entityManager}" 
               auto-create="true"/>

  <persistence:managed-persistence-context 
               name="entityManager" 
               auto-create="true"
               entity-manager-factory="#{entityManagerFactory}"/>

  <persistence:entity-manager-factory 
               name="entityManagerFactory" 
               auto-create="true" 
               persistence-unit-name="MyProjectPU"/>

Note: I had to change <core:init/> configuration as well, removing debug=true and jndi-pattern=jndiPattern.

4) Configure application log, because after changing <core:init/> configuration, I've lost the log information from my application:

# log4j.properties
log4j.rootLogger=info, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%c] %m%n

5) Change persistence unit, as said above, in persistence.xml:

From this:

  <jta-data-source>java:/MyProjectDatasource</jta-data-source>

To:

  <non-jta-data-source>java:comp/env/MyProjectDatasource</non-jta-data-source>

Note: I had to remove another configuration in persistence.xml:

      <property name="jboss.entity.manager.factory.jndi.name" value="java:/MyProjectEntityManagerFactory"/>

6) And, finally, put the necessary libraries in WEB-INF/lib. They are all the JAR files of your EAR archive and the files below (present on seam distribution):

antlr.jar
cglib-nodep.jar
commons-logging.jar
commons-collections.jar
dom4j.jar
hibernate-annotations.jar
hibernate-core.jar
hibernate-commons-annotations.jar
hibernate-entitymanager.jar
hibernate-validator.jar
javassist.jar
jsf-api.jar
jsf-impl.jar
jsf-facelets.jar
jta.jar
jboss-common-core.jar
jboss-el.jar
log4j.jar
persistence-api.jar
slf4j-api.jar
slf4j-log4j12.jar
 
28. May 2010, 14:19 America/New_York | Link
I've followed both original and Igor Lucases examples but outcome is the same:

May 28, 2010 3:08:11 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/lib/jvm/java-6-sun-1.6.0.20/jre/lib/i386/server:/usr/lib/jvm/java-6-sun-1.6.0.20/jre/lib/i386:/usr/lib/jvm/java-6-sun-1.6.0.20/jre/../lib/i386:/usr/java/packages/lib/i386:/lib:/usr/lib
May 28, 2010 3:08:11 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
May 28, 2010 3:08:11 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 968 ms
May 28, 2010 3:08:11 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
May 28, 2010 3:08:11 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.26
May 28, 2010 3:08:12 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive project.war
May 28, 2010 3:08:13 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
May 28, 2010 3:08:13 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/project] startup failed due to previous errors
May 28, 2010 3:08:13 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory ROOT
May 28, 2010 3:08:13 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory examples
May 28, 2010 3:08:13 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory host-manager
May 28, 2010 3:08:13 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory manager
May 28, 2010 3:08:14 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory docs
May 28, 2010 3:08:14 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
May 28, 2010 3:08:14 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
May 28, 2010 3:08:14 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/22 config=null
May 28, 2010 3:08:14 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2515 ms


Does anyone have any information?
 
15. Mar 2011, 12:33 America/New_York | Link

Hi. To solve this problem you should set logging level for class org.apache.catalina.core.StandardContext by adding to your {tomcat-home}/conf/logging.properties file this code:

org.apache.catalina.core.StandardContext.level = DEBUG

So, you can see details about this error in your log file