【问题标题】:How to include dependency classes in my eclipse(juno) project?如何在我的 eclipse(juno) 项目中包含依赖类?
【发布时间】:2016-01-02 23:56:42
【问题描述】:

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

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

奇怪的是,所有的 jars 都添加到 libraries 下,直到昨天一切正常!!

编辑:我在 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>

【问题讨论】:

    标签: java eclipse servlets


    【解决方案1】:

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

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

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

    【讨论】:

    • 看起来不错,您是否尝试删除所有库,然后再添加一次?
    • 复制以前的库并再次添加它们对我有用,因此替换以前的库也可以正常工作!但是有什么想法为什么会突然发生?这是否意味着日食(不使用 MAVEN)不稳定?
    • Eclipse 在依赖方面总是存在一些问题 :(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-27
    • 1970-01-01
    • 2014-04-24
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 2014-04-04
    相关资源
    最近更新 更多