aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes How does Maven deploy spring jars for Spring MVC servlet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "How does Maven deploy spring jars for Spring MVC servlet?" Watch "How does Maven deploy spring jars for Spring MVC servlet?" New topic
Author

How does Maven deploy spring jars for Spring MVC servlet?

Siegfried Heintze
Ranch Hand

Joined: Aug 11, 2000
Posts: 388
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
Bartender

Joined: Jan 17, 2008
Posts: 2409
    
  28

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

Joined: Aug 11, 2000
Posts: 388
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

Joined: Jun 25, 2001
Posts: 16145
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
jQuery in Action, 2nd edition
 
subject: How does Maven deploy spring jars for Spring MVC servlet?