Errai 4 running on Tomcat [closed]

谁说胖子不能爱 提交于 2019-12-05 21:22:00

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>
STB Land

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!