Search code examples
javamavenjava-ee-7eclipse-lunatomcat8

Tomcat 8 + Maven + Java EE 7 Web Profile


I'm trying to use Tomcat 8 as the server for a new web application. I'm going to use a lot of the java EE 7 web profile technologies, among them, the EJB Lite specification.

The web app project consists, in fact, of several other maven projects. I have a rest-api project (which uses JAX-RS 2.0), a business project (currently packaged as a jar) and domain project (also a jar). I have some set of common dependencies, which i packaged in a separate module "common-deps" (pom package). Among theses dependencies, is the java ee 7 web profile specification. All the other projects depend on the "common-deps" project.

Next is the pom.xml for the common-deps project:

    <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>
      <groupId>....</groupId>
      <artifactId>commons-deps</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <packaging>pom</packaging>
      <name>Common dependencies</name>

      <properties>
        <cdi.version>1.1</cdi.version>
        <sl4j.version>1.7.7</sl4j.version>
        <log4j.version>1.2.17</log4j.version>
        <junit.version>4.11</junit.version>
      </properties>

      <dependencies>

      <dependency> 
           <groupId>javax</groupId>   
            <artifactId>javaee-web-api</artifactId>   
            <version>7.0</version>
            <scope>provided</scope> 
      </dependency> 
  <!--  
    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <version>${cdi.version}</version>
        <scope>provided</scope>
    </dependency> 
  -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${sl4j.version}</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>${sl4j.version}</version>
    </dependency>

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>${log4j.version}</version>
    </dependency>

    <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>${junit.version}</version>
         <scope>test</scope>
     </dependency>
  </dependencies>

</project>

The thing is that when i try to create a stateless session bean with the @Stateless annotation, this annotation is not found. I don't know why is this, perhaps the javaee-web-api scope shouldn't be provided? But, as far as i understand, tomcat 8 should support this profile... perhaps it is because i'm missing a concrete implementation of some of the java ee apis? If this is indeed the case, should i specify the implementation for every api inside the java ee web profile? And, what implementation should i choose for the ejb lite api?

I searched everywhere but i could not find any tutorial about developing a java ee 7 web app with tomcat 8, and as i'm new to the java ee stack (coming from Spring) i must be doing something wrong. I'm using Eclipse Luna as IDE.

Excuse my poor english!


Solution

  • Ok, i understand now what's happening. It appears that dependencies with provided scope can't be transitive, which is exactly what i was hoping! (Can Maven's provided scoping, be transitive?)

    Thanks anyway!!