Reputation: 319
I am using IntelliJ 14
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.
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 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)
The project is exactly the same, I just use Maven for use the lib.
Do you have ideas?
My Servlet line 47 for example :
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
DateTime dt = new DateTime();
Integer jourDuMois = dt.getDayOfMonth();
}
Upvotes: 1
Views: 9697
Reputation: 319
Thank MWiesner, you for your Answer. It work.
I found another solution:
I dont know if is it possible for IntelliJ to do that automatically when maven import the lib ?
Upvotes: 3
Reputation: 9043
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
.
so You should have:
<packaging>war</packaging>
See also for reference: Maven Reference Book
Upvotes: 3
Reputation: 3321
The problem is more likely the joda-time jar is not included when you deploy the project. You can unzip the war file and see if it's there. I use Eclipse, which installs Maven plugin. So when I export the Maven project, all the Maven managed jars will be included in the war.
Upvotes: 0