0 Replies Latest reply on May 10, 2013 3:01 PM by Chris Harris

    Tomcat 7 + Weld 2.0 + JSF 2.2

    Chris Harris Newbie

      Hi.

       

      I've gotten Weld 2.0.0.Final and JSF 2.2 working on Tomcat 7.

       

      I can't find any information or examples when searching on the internet, so I thought that I'd pass along the relevant sections of my pom.xml.

       

      Does anyone have any suggestions for improvements for my pom.xml or weld-related sections of my tomcat context.xml and web.xml?

       

      I'm used to dealing with WAS on a daily basis and relying on the provided api's.  This pom.xml info comes from a personal site of mine hosted on Tomcat 7, so someone may have constructive criticisms on my integration effort (for instance, the javaee-endorsed-api bit within the maven-dependency-plugin at the bottom).  I used NetBeans to build this project.  The .jar's marked as provided are sitting within the lib folder of my Tomcat installation.

       

      My pom.xml

      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

               xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

          <modelVersion>4.0.0</modelVersion>

       

         <!-- I omitted the artifact info -->

       

      <properties>

              <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>

              <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

              <com.sun.faces.version>[2.0.1,)</com.sun.faces.version>

              <netbeans.hint.deploy.server>Tomcat</netbeans.hint.deploy.server>

              <org.hibernate.version>4.1.11.Final</org.hibernate.version>

          </properties>

       

          <dependencies>

              <!-- Servlet Spec 3.0 -->

              <dependency> 

                  <groupId>org.apache.tomcat</groupId> 

                  <artifactId>tomcat-servlet-api</artifactId> 

                  <version>7.0.39</version> 

                  <scope>provided</scope> 

              </dependency>

             

              <!-- JSF 2.x Begin -->

              <dependency>

                  <groupId>com.sun.faces</groupId>

                  <artifactId>jsf-api</artifactId>

                  <version>${com.sun.faces.version}</version>

              </dependency>

              <dependency>

                  <groupId>com.sun.faces</groupId>

                  <artifactId>jsf-impl</artifactId>

                  <version>${com.sun.faces.version}</version>

              </dependency>

              <dependency>

                  <groupId>javax.servlet.jsp</groupId>

                  <artifactId>jsp-api</artifactId>

                  <version>2.2.1-b03</version>

                  <scope>provided</scope>

              </dependency>

              <dependency>

                  <groupId>javax.servlet</groupId>

                  <artifactId>jstl</artifactId>

                  <version>1.2</version>

                  <scope>runtime</scope>

              </dependency>

              <dependency>

                  <groupId>taglibs</groupId>

                  <artifactId>standard</artifactId>

                  <version>1.1.2</version>

              </dependency>

              <!-- JSF 2.x End -->

             

              <!-- Weld/CDI Begin -->

              <dependency>

                  <groupId>javax.enterprise</groupId>

                  <artifactId>cdi-api</artifactId>

                  <scope>provided</scope>

                  <version>1.1</version>

              </dependency>

              <dependency>

                  <groupId>org.jboss.weld.servlet</groupId>

                  <artifactId>weld-servlet</artifactId>

                  <version>2.0.0.Final</version>

                  <scope>runtime</scope>

              </dependency><!--

               Enables common annotations,

                   which is provided by default in an EE container, on Tomcat Begin-->       

              <dependency>

                  <groupId>org.glassfish.web</groupId>

                  <artifactId>el-impl</artifactId>

                  <version>2.2.1-b05</version>

                  <scope>runtime</scope>

                  <exclusions>

                      <exclusion>

                          <groupId>javax.el</groupId>

                          <artifactId>el-api</artifactId>

                      </exclusion>

                  </exclusions>

              </dependency>

              <dependency>

                  <groupId>javax.annotation</groupId>

                  <artifactId>jsr250-api</artifactId>

                  <version>1.0</version>

              </dependency>

             

              <!-- Bean Validation API (JSR 303) -->

              <dependency>

                  <groupId>javax.validation</groupId>

                  <artifactId>validation-api</artifactId>

                  <version>1.0.0.GA</version>

              </dependency>

              <!-- Enables common annotations,

                   which is provided by default in an EE container, on Tomcat End-->

              <!-- Weld/CDI End -->

             

              <!-- PrimeFaces Begin -->

              <dependency>

                  <groupId>org.primefaces</groupId>

                  <artifactId>primefaces</artifactId>

                  <version>3.5</version>

              </dependency>

             

              <dependency>

                  <groupId>org.primefaces</groupId>

                  <artifactId>primefaces-mobile</artifactId>

                  <version>0.9.3</version>

              </dependency>

         

              <dependency>

                  <groupId>commons-fileupload</groupId>

                  <artifactId>commons-fileupload</artifactId>

                  <version>1.2.2</version>

              </dependency>

             

              <!-- Database driver Begin -->

              <dependency>

                  <groupId>postgresql</groupId>

                  <artifactId>postgresql</artifactId>

                  <version>9.1-901.jdbc4</version>

                  <scope>provided</scope>

              </dependency>

              <!-- Database driver End -->

             

              <!-- Hibernate/JPA 2.0 Begin -->

              <dependency>

                  <groupId>org.hibernate</groupId>

                  <artifactId>hibernate-core</artifactId>

                  <version>${org.hibernate.version}</version>

              </dependency>

              <dependency>

                  <groupId>org.hibernate</groupId>

                  <artifactId>hibernate-entitymanager</artifactId>

                  <version>${org.hibernate.version}</version>

              </dependency>

              <dependency>

                  <groupId>org.hibernate</groupId>

                  <artifactId>hibernate-validator</artifactId>

                  <version>4.3.0.Final</version>

              </dependency>

              <!-- Hibernate uses slf4j for logging, for our purposes here use the simple backend -->

              <dependency>

                  <groupId>org.slf4j</groupId>

                  <artifactId>slf4j-simple</artifactId>

                  <version>1.6.6</version>

              </dependency>

              <!-- Hibernate/JPA 2.0 End -->

             

              <!-- BoneCP Begin -->

              <dependency>

                  <groupId>com.jolbox</groupId>

                  <artifactId>bonecp</artifactId>

                  <version>0.8.0-rc1</version>

              </dependency>

              <dependency>

                  <groupId>com.jolbox</groupId>

                  <artifactId>bonecp-provider</artifactId>

                  <version>0.8.0-alpha1</version>

              </dependency>

              <!-- BoneCP End -->

             

              <dependency>

                  <groupId>javax.mail</groupId>

                  <artifactId>mail</artifactId>

                  <version>1.4.5</version>

              </dependency>

          </dependencies>

       

       

          <build>

              <finalName>os</finalName>

              <plugins>

                  <plugin>

                      <groupId>org.apache.maven.plugins</groupId>

                      <artifactId>maven-compiler-plugin</artifactId>

                      <version>2.3.2</version>

                      <configuration>

                          <source>1.7</source>

                          <target>1.7</target>

                          <compilerArguments>

                              <endorseddirs>${endorsed.dir}</endorseddirs>

                          </compilerArguments>

                      </configuration>

                  </plugin>

                  <plugin>

                      <groupId>org.apache.maven.plugins</groupId>

                      <artifactId>maven-war-plugin</artifactId>

                      <version>2.2</version>

                      <configuration>

                          <failOnMissingWebXml>false</failOnMissingWebXml>

                      </configuration>

                  </plugin>

                  <plugin>

                      <groupId>org.apache.maven.plugins</groupId>

                      <artifactId>maven-dependency-plugin</artifactId>

                      <version>2.4</version>

                      <executions>

                          <execution>

                              <phase>validate</phase>

                              <goals>

                                  <goal>copy</goal>

                              </goals>

                              <configuration>

                                  <outputDirectory>${endorsed.dir}</outputDirectory>

                                  <silent>true</silent>

                                  <artifactItems>

                                      <artifactItem>

                                          <groupId>javax</groupId>

                                          <artifactId>javaee-endorsed-api</artifactId>

                                          <version>6.0</version>

                                          <type>jar</type>

                                      </artifactItem>

                                  </artifactItems>

                              </configuration>

                          </execution>

                      </executions>

                  </plugin>

              </plugins>

          </build>

         

          <repositories>

              <repository>

                  <id>prime-repo</id>

                  <name>PrimeFaces Maven Repository</name>

                  <url>http://repository.primefaces.org</url>

                  <layout>default</layout>

              </repository>

          </repositories>

      </project>

       

      My Tomcat 7 context.xml

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

      <Context antiJARLocking="true" path="/os">

        <!-- disable storage of sessions across restarts -->

        <Manager pathname=""/>

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

        <!-- Uncomment to enable injection into Servlet -->

        <!--    <Listener className="org.jboss.weld.environment.tomcat.WeldLifecycleListener"/> -->

      </Context>

       

       

      My weld-related section from web.xml:

          <!-- Required by Weld/CDI since we're using Tomcat and not a full JEE container -->

          <listener>

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

          </listener>

          <resource-env-ref>

              <description>Object factory for the CDI Bean Manager</description>

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