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

标签 java jsf maven

我在 Eclipse 中有两个 Web 项目:Framework 和 webxxx

在我的框架中,我有一些 utils复制、下载、上传等功能...

当我从webxxx调用下载方法时我得到了*java.lang.NoClassDefFoundError: javax/faces/context/FacesContext*.

如果我搬家GerenciarArquivo类到 webxxx 项目 downloadFile 方法工作正常。

框架:

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

WEBXXX 项目:

GerenciarArquivo.downloadFile(abb.getPath());

两个项目都有:

enter image description here enter image description here

Web xxx 项目依赖项:

<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>

框架依赖项:

<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>

最佳答案

添加此依赖项,这解决了我的问题

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>

关于java.lang.NoClassDefFoundError : javax/faces/context/FacesContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19812574/

相关文章:

java - 内部 JSON 对象的 GWT Java 覆盖

jsf - 将@ManagedBean 切换为@Named 后 : javax. el.PropertyNotFoundException : Target Unreachable, 标识符 'person' 解析为空

java - 使用多个源文件夹(作为将大型 Java 项目转换为 Maven 的中间步骤)

maven-pax-provision + equinox : java. lang.Long 无法转换为 java.lang.String

Java 堆栈查看

java - 在 Android 中返回特定位图而不是整个 View

java - 路径变量不映射 Spring MVC

jsf - 如何传递整数常量

css - 使用 <p :rowToggler/> with Text as Label instead Symbol of toggler

java - 多模块 Spring Boot 配置