0

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>
Al2x
  • 1,001
  • 5
  • 26
  • 37
  • Primefaces upload component needs commons-fileupload. do you have it? – erencan Nov 06 '13 at 12:54
  • Avoid including code as images. Just paste your code as text in a code block (4 spaces indentation) – rzymek Nov 06 '13 at 13:00
  • @Al2x Could you try with JSF 2.2.4 (javax.faces-2.2.4.jar) and servlet version 3.0? And make sure you've included jar in your classpath please. – Ömer Faruk Almalı Nov 06 '13 at 14:07
  • in addition to commons-fileupload.jar, commons-ui.jar and commons-el.jar are also needed. – erencan Nov 06 '13 at 14:20
  • Im getting this error : java.lang.ClassNotFoundException: javax.faces.context.FacesContext from [Module "deployment.Servicoxxx.ear.framework-1.0.0-SNAPSHOT.jar:main" from Service Module Loader] @ÖmerFarukAlmalı – Al2x Nov 06 '13 at 15:28
  • You have two (or more) distributions of JSF available within your webapp server. Find the duplicate and delete it – kolossus Nov 06 '13 at 20:41
  • @kolossus: I don't think so. The `NoClassDefFoundError` doesn't indicate that. Also, *"If I move GerenciarArquivo class to webxxx project the downloadFile method works fine."*. Most likely, his Maven config is simply messed up. – BalusC Nov 07 '13 at 09:34
  • @balusC these are my maven config. – Al2x Nov 07 '13 at 09:56
  • I don't do Maven, so I can't really go in detail, but the Java EE API should **always** be provided and not be included in build. It's namely the target Java EE container like GlassFish, JBoss AS, etc who is supposed to already provide it out the box. As to JSF API/impl, that depends on target container make/version which you didn't tell anything about in your question. For example a barebones JSP/Servlet container like Tomcat doesn't ship with JSF bundled and therefore JSF API/impl should be included in the build. – BalusC Nov 07 '13 at 09:59

2 Answers2

6

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>
Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
Reetika
  • 1,227
  • 2
  • 17
  • 24
  • It worked.... I realized also that I need to create in framework project the facesconfig.xml inside META-INF folder. The facesconfig.xml can be empty. – Al2x Mar 19 '15 at 13:44
-1

Go to your Oracle->middleware->module-> and copy javax.jsf_1.2.0.1.jar and paste it in your EAR->APP-INF->lib folder and restart your server. Worked for me