Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet, tomcat doesn't see javaee-api-7.0-b83.jar

I am trying to run sample guessnumber-jsf from Java EE tutorial. It is here: https://svn.java.net/svn/javaeetutorial~svn

There is no dependencies in pom.xml. So output file has no .jar file. When I try to put javaee-api-7.0-b83.jar inside tomcat/lib or WEB-INF/lib/javaee-api-7.0-b83.jar, nothing changes.

When I try to open

localhost:8080/guessnumber-jsf/faces/greeting.xhtml

I get ClassNotFoundException. Where can I get list of jars that I need for faces tutorial? How can I connect them?

like image 728
Stepan Yakovenko Avatar asked Apr 14 '13 18:04

Stepan Yakovenko


3 Answers

You can't put that Java EE jar in Tomcat and expect it to magically morph into a Java EE server.

That particular jar only contains the APIs to link against (eg "headers" in C/C++ terminology). It does not contain any implementation.

The easiest thing to do is to dish Tomcat and download TomEE instead. Optionally download GlassFish.

These will all already contain all the functionality you need and nothing will have to be put into WEB-INF/lib. (if using Maven put the Java EE 6 GAV as a dependency with scope provided in your pom).

like image 162
Mike Braun Avatar answered Nov 07 '22 07:11

Mike Braun


If you are using a Maven project you can fix this error by adding the following dependency:

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.faces</artifactId>
    <version>2.2.7</version>
</dependency>
like image 43
Stan Avatar answered Nov 07 '22 08:11

Stan


Adding to the answer of Mike Braun, the Java EE 6 GAV for the web profile is:

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-web-api</artifactId>
    <version>6</version>
    <scope>provided</scope>
</dependency>

Specifically note the scope: "provided". This means your Maven project will link against this, but it expects your runtime to have the implementations. For TomEE, GlassFish, JBoss AS 7.x, etc this is indeed the case.

like image 31
Arjan Tijms Avatar answered Nov 07 '22 07:11

Arjan Tijms