Al2x Al2x -3 years ago 196
Java Question

java.lang.NoClassDefFoundError: javax/faces/context/FacesContext

I have two web projects in Eclipse: Framework and webxxx

In my framework I have some

utils
functions like copy, download, upload,etc...

When I call download method from
webxxx
I got
*java.lang.NoClassDefFoundError: javax/faces/context/FacesContext*.


If I move
GerenciarArquivo
class to webxxx project the downloadFile method works fine.

FRAMEWORK :

public abstract class GerenciarArquivo{
...
public static void downloadFile(String filePath) throws IOException{
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) context
.getExternalContext().getResponse();


WEBXXX PROJECT :

GerenciarArquivo.downloadFile(abb.getPath());


Both projects has :

enter image description here
enter image description here

Web xxx project Dependencies :

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

<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.5</version>
</dependency>

<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>all-themes</artifactId>
<version>1.0.9</version>
</dependency>


<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.4</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.4</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0-alpha-1</version>
<scope>provided</scope>
</dependency>


Framework dependencies :

<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.9.Final</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.2</version>
</dependency>
</dependencies>

Answer Source

Add this dependency, this resolve my problem of

class not found exception : javax.faces.context.facesContext .

<dependency>
     <groupId>javax</groupId>
     <artifactId>javaee-web-api</artifactId>
     <version>6.0</version>
     <scope>provided</scope>
</dependency>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download