获取缺少运行时依赖项的错误

获取缺少运行时依赖项的错误

本文介绍了获取缺少运行时依赖项的错误:java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置 Maven、JSF 和 Primefaces 项目.但是当我运行项目时出现以下错误

I am trying to setup Maven, JSF and Primefaces project. But when i run the project i get the following error

com.sun.faces.config.ConfigurationException:
Source Document: jar:file:/D:/Personal%20Work/eclipse%2032%20Bit/workspace/Java%20EE
/Spring/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps
/ch18_SpringWebFlowAndJSF/WEB-INF/lib/primefaces-3.5.jar!/META-INF/faces-config.xml
Cause: Class 'org.primefaces.component.fileupload.FileUploadRenderer' is missing
 a runtime dependency: java.lang.NoClassDefFoundError: org/apache/commons/fileupload
/FileItem

这是我的 POM 片段

Here is my POM snippet

<properties>
    <java-version>1.6</java-version>
    <org.springframework-version>3.2.3.RELEASE</org.springframework-version>
    <org.aspectj-version>1.6.10</org.aspectj-version>
    <org.slf4j-version>1.7.5</org.slf4j-version>
    <jsf-version>2.2.0</jsf-version>
</properties>

    <dependency>
        <groupId>org.springframework.webflow</groupId>
        <artifactId>spring-faces</artifactId>
        <version>2.3.2.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>${jsf-version}</version>
    </dependency>

    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>${jsf-version}</version>
    </dependency>

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

<repositories>
    <repository>
        <id>prime-repo</id>
        <name>PrimeFaces Maven Repository</name>
        <url>http://repository.primefaces.org</url>
        <layout>default</layout>
    </repository>
</repositories>

为什么我会收到这个错误?

Why i am getting this error?

谢谢

推荐答案

java doc

NoClassDefFoundError 如果 Java 虚拟机或ClassLoader 实例尝试加载类的定义(如正常方法调用的一部分或作为创建新实例的一部分使用 new 表达式)并且不能定义类找到了.

当前执行时,搜索到的类定义存在类已编译,但无法再找到定义.

The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.

org.apache.commons.fileupload.FileItem 是 Apache Commons 的 FileUpload 组件中的一个类,它在您的类路径中缺失.在 pom.xml 中为 FileUpload 组件添加以下 maven 依赖项.

org.apache.commons.fileupload.FileItem is a class in FileUpload component of Apache Commons which is missing in your class path. Add following maven dependency for FileUpload component in your pom.xml.

 <dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>x.x</version>
 </dependency>

您还可以查看BalusC的这个答案

这篇关于获取缺少运行时依赖项的错误:java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 19:54