java - 如何在我的 eclipse(juno) 项目中包含依赖项类?

标签 java eclipse servlets

我将所有 jar 文件保存在 Web-content/WEB-INF/lib 中,并构建到 Java-Resources/Libraries 中。我的项目过去两周一直运行良好,但是今天突然所有依赖项都抛出 ClassNotFoundException。请帮忙。

我还尝试将所有 jar 保存在另一个文件夹中,并使用 Java 构建路径 > 库添加它们。

奇怪的是,所有 jar 都添加到下,并且直到昨天一切都工作正常!!

编辑:我在 WEB-INF/lib 中制作了两个 jar 副本(简单的复制粘贴),并再次使用构建路径添加了它们(新副本)(因此,现在每个都有两个实例)。这解决了问题。 对于为什么会发生这种情况有什么看法吗?

编辑 2:我的类路径文件:(当我尝试不同的方法来解决我的问题时,创建了 jar 文件和“依赖项”文件夹的多个副本)

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.7.0_45">
        <attributes>
            <attribute name="owner.project.facets" value="java"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0">
        <attributes>
            <attribute name="owner.project.facets" value="jst.web"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>

    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/jstl-1.2.jar"/>

    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-codec-1.9.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/poi-ooxml-3.13-20150929.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/poi-ooxml-schemas-3.13-20150929.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/xmlbeans-2.6.0.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-logging-1.1.3.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/junit-4.12.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/log4j-1.2.17.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/poi-excelant-3.13-20150929.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/poi-scratchpad-3.13-20150929.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-fileupload-1.3.1.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-io-2.4.jar"/>
    <classpathentry kind="lib" path="WebContent/dependecies/commons-codec-1.9.jar"/>
    <classpathentry kind="lib" path="WebContent/dependecies/commons-fileupload-1.3.1.jar"/>
    <classpathentry kind="lib" path="WebContent/dependecies/commons-io-2.4.jar"/>
    <classpathentry kind="lib" path="WebContent/dependecies/commons-logging-1.1.3.jar"/>
    <classpathentry kind="lib" path="WebContent/dependecies/jstl-1.2.jar"/>
    <classpathentry kind="lib" path="WebContent/dependecies/junit-4.12.jar"/>
    <classpathentry kind="lib" path="WebContent/dependecies/log4j-1.2.17.jar"/>
    <classpathentry kind="lib" path="WebContent/dependecies/poi-excelant-3.13-20150929.jar"/>
    <classpathentry kind="lib" path="WebContent/dependecies/poi-ooxml-3.13-20150929.jar"/>
    <classpathentry kind="lib" path="WebContent/dependecies/poi-ooxml-schemas-3.13-20150929.jar"/>
    <classpathentry kind="lib" path="WebContent/dependecies/poi-scratchpad-3.13-20150929.jar"/>
    <classpathentry kind="lib" path="WebContent/dependecies/xmlbeans-2.6.0.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/mysql-connector-java.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/mysql-connector-java-5.1.13-bin.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/Copy of jstl-1.2.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/poi-3.13-20150929.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/Copy of poi-3.13-20150929.jar"/>
    <classpathentry kind="output" path="build/classes"/>
</classpath>

最佳答案

一般来说,如果您通过其他软件管理依赖项,那么维护您的项目就会简单得多。

如果您的引用资料有问题,您应该使用 MAVEN (MVN)。然后 eclipse 将解析您所有依赖的 JAR 并正确配置您的 eclipse。

如果您想继续使用 Eclipse,请将项目中的 .classpath 文件粘贴到此处。

关于java - 如何在我的 eclipse(juno) 项目中包含依赖项类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32963646/

相关文章:

java - 通过 Spring MVC Web 应用程序向客户端发送文本文件

java - 将两个类相互连接

java - Java 中的字符类

java - Grails - 将 Maven 依赖项添加到 Eclipse 类路径

java - 如何在文本文件更改时重新初始化 java servlet

java - 重定向代码后仍然从上一页执行

java - 无法在 Firefox 中拖放 Web 驱动程序

java - 使用 EC2 托管 Java Web 服务的最佳实践

android - 在不打开邮箱的情况下使用 PhoneGap 发送邮件

eclipse - Eclipse 中未定义的 CSS/JavaScript/Image 文件