• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How does Maven deploy spring jars for Spring MVC servlet?

 
Siegfried Heintze
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to make a sample at http://www.deepakgaikwad.net/index.php/2009/02/08/spring-mvc-tutorial-with-eclipse-and-tomcat.html work with maven and I'm getting a stack trace indicating that jetty cannot load org.springframework.web.servlet.DispatcherServlet.

I tried it first hoping maven would copy the necessary jars into the WEB-INF/lib directory automagically. Perhaps I need to insert a special clause in the pom.xml? I later tried manually copying the jar files into the WEB-INF/lib (like the tutorial said to do) and this did not seem to help... So maybe this is the wrong directory? I was hoping to make maven copy to the correct directory (what is the correct directory?) so jetty can load the spring classes. How do I make Maven deploy a WAR file with the spring jars? Is WEB-INF/lib the correct directory? (Do I need to post that question separately in the JEE/Servlet forum?)

I was also studying the pom.xml for http://www.objectdb.com/tutorial/jpa/eclipse/web. The downloadable source code (as opposed to the source code in the text) actually works and I cannot figure out how or why the necessary jar files are eventually put in the WAR files so jetty can call spring to run the servlet. How does this work? Where in the pom.xml is maven instructed to copy the required jar files to the WAR file? Does it have to do with the "scope" feature of the dependency?

Thanks!
Siegfried
 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The tutorial is wrong because it's not a maven tutorial. To add dependencies into a maven, you have to add the dependencies into the pom.xml. You shouldn't add it to eclipse. When you add it it pom.xml, Maven will automatically include the dependencies into your compile path, and also when you package the war, it will automatically put the dependencies into the WEB-INF/lib folder.

By adding the dependent libraries manually into Eclipse, you are circumventing Maven. Hence, Maven doesn't package it for you.
 
Siegfried Heintze
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh yeah -- Sorry I did not make myself clear. I added the dependencies using the maven plugin for eclipse. When that did not work I tried manually adding them to the WEB-INF/lib directory. The first tutorial was not a maven tutorial and I was trying to use maven with it. So how does maven know how to copy the jar files to the WAR?

Thanks
Siegfried
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jars that are declared as Maven dependencies in the POM will automatically be copied from the maven repository (cache) into the target WAR's WEB-INF/lib directory as long as they have the default (compile) scope.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic