【问题标题】:JAVA EE & Eclipse: I am getting java.lang.NoClassDefFoundError even though I have set the build pathJAVA EE & Eclipse:我收到 java.lang.NoClassDefFoundError 即使我已经设置了构建路径
【发布时间】:2014-03-01 17:43:57
【问题描述】:

我正在使用带有 Google App Engine 插件的 Eclipse。我正在尝试运行一个添加了 joda 时间的简单程序。似乎该错误与构建路径有关,我按照以下说明进行操作: https://stackoverflow.com/a/12105417/3255963 但我仍然收到以下错误。接下来我需要做什么?

package test;
import java.io.IOException;
import javax.servlet.http.*;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

@SuppressWarnings("serial")
public class testServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {

        DateTime newYears = new DateTime (2014, 1, 1, 0, 0);

        resp.setContentType("text/plain");
        resp.getWriter().println("Hello, world");

    }

}       

错误:

java.lang.NoClassDefFoundError: org/joda/time/DateTime

我在项目资源管理器和构建路径中看到了 joda-time-2.3.jar。

我也尝试在 order 和 export 下选择它。

【问题讨论】:

    标签: eclipse jakarta-ee java


    【解决方案1】:

    Java 中的 NoClassDefFoundError 出现在 Java 虚拟机无法在运行时找到在编译期间可用的特定类时。 请确认你是否有req。项目资源管理器中 \WebContent\WEB-INF\lib 下的 jars 以及项目构建路径。

    【讨论】:

    • 谢谢!做到了。将来有没有自动的方法来做到这一点?我是否还需要在 libs 文件夹中有 jar? (我会支持你,但我的声誉还不够高。)
    • 据我所知,没有自动的方法可以做到这一点,每次您在 Java Web 应用程序中使用 jar 时,都需要将其添加到 lib 文件夹以及 Build 路径中.这是因为当您以war文件的形式导入项目时,IDE会自动将lib文件夹下的jar打包到您的Web应用程序中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-19
    • 2011-10-04
    • 2015-09-30
    • 2020-03-05
    • 2017-12-24
    • 2019-10-12
    • 2020-07-24
    相关资源
    最近更新 更多