Errai 4 running on Tomcat

444 views Asked by At

I am attempting to get Errai 4.0.0.Beta1 running in Tomcat, and I was wondering if anyone has done this before? Specifically, I am trying to determine what dependencies I can remove from Errai (i.e. Wildfly), and any additional steps required to get an Errai application running on Tomcat.

When I get this running, I will update this post.

Thanks in advance.

2

There are 2 answers

2
Stéphane B. On BEST ANSWER

To show how to run an Errai 4 Maven project on Tomcat server, I created a project on GitHub called errai-tutorial-tomcat.

Prerequisites

Your Errai webapp must be installed on your local Maven repository ( mvn install )

Create a new Maven project (war packaging) and import your previous webapp

for example : errai-tutorial (https://github.com/errai/errai-tutorial)

    <dependency>
        <groupId>org.jboss.errai.demo</groupId>
        <artifactId>errai-tutorial</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <type>war</type>
    </dependency>

Add Tomcat missing dependencies

  1. Weld Servlet Core ( https://docs.jboss.org/weld/reference/2.3.4.Final/en-US/html/environments.html#weld-servlet )

    <dependency>
        <groupId>org.jboss.weld.servlet</groupId>
        <artifactId>weld-servlet-core</artifactId>
        <version>2.3.4.Final</version>
    </dependency>        
    
  2. Jersey JAX-RS core Servlet 2.x implementation

    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet-core</artifactId>
        <version>2.23.1</version>
    </dependency>
    
  3. Hibernate definition of the Java Persistence 2.0 (JSR 317) API.

    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>1.0.1.Final</version>
    </dependency>
    

Add Weld Servlet listener in Web.xml file

<listener>
  <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>

Add BeanManager reference in Web.xml file

<resource-env-ref>     
    <resource-env-ref-name>BeanManager</resource-env-ref-name>
    <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager </resource-env-ref-type>
</resource-env-ref>

Add Jersey JAX-RS core Servlet in Web.xml file

<servlet> 
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <servlet-name>javax.ws.rs.core.Application</servlet-name> 
    <load-on-startup>2</load-on-startup> 
</servlet>

Add context.xml file in META-INF directory

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

    <Resource name="BeanManager"
                  auth="Container"
                  type="javax.enterprise.inject.spi.BeanManager"
                  factory="org.jboss.weld.resources.ManagerObjectFactory"/>

</Context>
0
Stéphane B. On

To show how to run an Errai 4 (4.1.3.Final) Maven project on Tomcat server (7.x or 8.x), I created another project from scratch on GitHub called test-errai4-tomcat.

For now, it display a simple form that can :

  • send message to server with the Errai Client Bus.
  • calling REST service with the Errai JAX-RS