Java EE:使用IntelliJ和Maven的NoClassDefFoundError org.joda.time.DateTime [英] Java EE: NoClassDefFoundError org.joda.time.DateTime with IntelliJ and Maven

查看:439
本文介绍了Java EE:使用IntelliJ和Maven的NoClassDefFoundError org.joda.time.DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用IntelliJ 14

I am using IntelliJ 14

我想在我的项目中添加joda.time lib. 当我手动添加此lib(将jar文件复制到lib存储库,并在Project Structure中添加引用)一切正常时,我可以在servlet中使用该库并在jsp中显示结果.

I want to add joda.time lib in my project. When I add this lib manually (copy the jar file into lib repository, and add reference in Project Structure) everything work good, I can use the library in a servlet and show the result in a jsp.

但是在第二步中,我创建了相同的项目,但是我将maven与pom.xml文件一起使用.我添加了此依赖项:

But in second step I create the same project but I am using maven with a pom.xml file. I add this dependency :

<dependencies>
    <dependency>
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.1</version>
    </dependency>
</dependencies>

Maven自动下载lib,在我的项目结构中,一切看起来都很好,我运行了项目...没有错误,但是当我转到网页时,导航器中出现错误:

Maven download automatically the lib, in my Project Structure every thing looks like it's good, I run the project ... no error, but when I go to my webpage I have an error in my navigator :

java.lang.NoClassDefFoundError: org/joda/time/DateTime
com.sdzee.servlets.ServletTest.doGet(ServletTest.java:47)
javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

项目完全相同,我只是使用Maven来使用lib.

The project is exactly the same, I just use Maven for use the lib.

您有想法吗?

例如,我的Servlet第47行:

My Servlet line 47 for example :

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    DateTime dt = new DateTime();
    Integer jourDuMois = dt.getDayOfMonth();
}

推荐答案

如果packaging type明确设置为war,则应签入pom.xml.否则,maven将不会使用maven-war-plugin将您的应用程序正确地与所有引用的库捆绑在一起,例如joda-time.

You should check in your pom.xml if the packaging type is explicitly set to war. If not, maven won't use the maven-war-plugin to bundle your application correctly with all your referenced libraries, e.g. joda-time.

所以您应该拥有:

<packaging>war</packaging>

另请参阅: Maven参考书

这篇关于Java EE:使用IntelliJ和Maven的NoClassDefFoundError org.joda.time.DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆