我在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 PROJECT:
GerenciarArquivo.downloadFile(abb.getPath());
两个项目都有:
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>
答案 0 :(得分:5)
添加此依赖项,这解决了我的问题
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>
答案 1 :(得分:-1)
转到您的Oracle-&gt;中间件 - &gt;模块 - &gt;并复制javax.jsf_1.2.0.1.jar并将其粘贴到您的EAR-&gt; APP-INF-&gt; lib文件夹中,然后重新启动您的服务器。为我工作