0

I am building a PoC for using JSF and am using Tomcat 7.0.59 as my server. My pom.xml looks like :

<repositories>
        <repository>
            <id>Java.Net</id>
            <url>http://download.java.net/maven/2/</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>6.0</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.1.7</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
        </dependency>
    </dependencies>

I looked up for the error and found out that it is caused due to the javaee-api but looks like even after adding that particular dependency the issue isn't resolving. There is a different thread but it is on different servers like glassfish, jboss and doesn't seem to be working on my case.

EDIT : After suggestions from Samuel and Tiny, I have reached to this pom.xml :

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.1</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.1.7</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

And maven dependency tree looks like :

 com.Sourabh:SourabhTest:war:0.1
[INFO] +- junit:junit:jar:3.8.1:test
[INFO] +- javax.faces:jsf-api:jar:2.1:compile
[INFO] \- com.sun.faces:jsf-impl:jar:2.1.7:compile
Sourabh
  • 1,253
  • 6
  • 21
  • 39
  • You are likely having multiple `FacesServlet`s on the class-path from more than one JAR file containing JSF APIs. You are running on Apache Tomcat. Why is `javaee-api` dependency needed? Tomcat is not a Java EE compliant container. Paste the tile in the Google search box. A match will be found within no time. – Tiny Feb 26 '15 at 10:55
  • I found [one](http://stackoverflow.com/a/8081384/1391249) of the best matches, by the way. – Tiny Feb 26 '15 at 10:58
  • @Tiny: okay so i removed javaee-api since tomcat is non-compliant to Java EE. but i am still facing issue. I have servlet 3.0, tomcat 7.0.59 and jsf 2.1 i think all three are compatible. – Sourabh Feb 26 '15 at 11:12

1 Answers1

0

Servlet-api must be flagged with <scope>provided</scope>, as the jar in provided by tomcat. If you don't you might encounter class loader issues.

To ensure that you don't have several time the same dependency (through transitive dep.) you can run mvn dependency:tree or go in the dependency hierarchy plugin in eclipse

Samuel EUSTACHI
  • 3,116
  • 19
  • 24
  • I was previously using 3.0.1 version for servlet api but since tomcat 7 provides servlet 3.0 I used `3.0.1` and `provided` but maven is branding it as missing artifact after i updated the project. – Sourabh Feb 26 '15 at 12:45
  • Can you update your answer with your pom, and the complete error message ? – Samuel EUSTACHI Feb 26 '15 at 12:49
  • 3.0 doesn't seem to be available on the maven central repo : http://mvnrepository.com/artifact/javax.servlet/javax.servlet-api – Samuel EUSTACHI Feb 26 '15 at 12:59
  • I think you can safely use 3.0.1 at compile time, ans 3.0 provided by tomcat at runtime – Samuel EUSTACHI Feb 26 '15 at 13:00
  • Exactly my thought... and its not working with 3.0.1. – Sourabh Feb 26 '15 at 13:00
  • I am using 2.3.1 as my maven compiler plugin although I don't it matters. – Sourabh Feb 26 '15 at 13:01
  • I undertood that you tried 3.0.1 without scope provided, and 3.0 with scope provided. Did you try 3.0.1 with scope provided ? – Samuel EUSTACHI Feb 26 '15 at 13:02
  • Yes I did that as well. – Sourabh Feb 26 '15 at 13:05
  • I am not sure whether it is just the pom.xml dependencies or could it be that the my build method that is flawed? – Sourabh Feb 26 '15 at 13:08
  • You can run maven dependency:tree or go in the "dependency hierarchy" tab in eclipse to see if you have this dependency imported as a transitivve dependency (by jsf for instance) – Samuel EUSTACHI Feb 26 '15 at 13:09
  • I don't think there is any transitive dependencies involved. For once I even removed servlet-api as I don't really require it right now in my project. Tomcat's servlet-api is suffice for runtime. – Sourabh Feb 26 '15 at 13:26
  • The same. No change. I had put in servlet jsp because the maven-archetype was selected to be webapp and I guess i brings in an index.jsp so I had to facilitate HTTPServlet for jsp. But I don't have business requirements of such. So I removed them both. But the error message is the same. – Sourabh Feb 26 '15 at 13:45
  • There must be several confilcting jars. Can you please post the result of mvn dependency:tree ? Is there any jsf jar in your tomcat shared libs ? – Samuel EUSTACHI Feb 26 '15 at 13:53
  • Done :) No I haven't configured tomcat shared lib. – Sourabh Feb 26 '15 at 14:11
  • 1
    Ok so it seems a specific jsf issue. I see a couple of possible fixes here : http://stackoverflow.com/questions/7807549/java-lang-classformaterror-absent-code-attribute-in-method-that-is-not-native-o If this doesn't you will have to ask balusc :) – Samuel EUSTACHI Feb 26 '15 at 15:06