Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

add lib jars to war file using maven

 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd like to use Spring framework with my web application. I put a bunch of spring jar files under WEB-INF/lib/ directory, I tried this:

when I run mvn, it gives error:

Missing:
----------
1) spring:spring:jar:2.0.8

Try downloading the file manually from the project website.

Then, install it using the command:
mvn install:install-file -DgroupId=spring -DartifactId=spring -Dversion=2.0.8 -Dpackaging=jar -Dfile=/path/to/file

Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=spring -DartifactId=spring -Dversion=2.0.8 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

Path to dependency:
1) com.sun.faces:VOCPortal:war:1.0
2) spring:spring:jar:2.0.8

----------
1 required artifact is missing.



Then I tried: mvn install:install-file -DgroupId=springLib -DartifactId=springLib -Dversion=2.0.8 -Dpackaging=jar -Dfile=WebContent/WEB-INF/lib/spring-core-2.0.8.jar

It compiles fine. But when I look at the generated war file, there is no lib directory under WEB-INF, and it failed to run in tomcat

How can I add other spring jar files to the war file? Thanks.

 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://maven.apache.org/ref/2.2.1/maven-model/maven.html#class_dependency" target="_new" rel="nofollow">systemPath is not recommended.

In any case, maven assumes your runtime environment provides "system" scoped libraries.

Maven will automatically package runtime-scoped libraries. Why are you keeping your required libraries in /WEB-INF/lib rather than letting Maven do its job and keep them non-local/etc.?
 
reubin haz
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

David Newton wrote:
Maven will automatically package runtime-scoped libraries. Why are you keeping your required libraries in /WEB-INF/lib rather than letting Maven do its job and keep them non-local/etc.?



Could you tell me what should be the correct way to use maven to handle those jar files?
I think specify each jar with a <dependency> in the pom.xml is too long if there are many jars.... and I don't like to always download jars since I often encounter download failure.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know how many dependencies you have, but there are a number of ways their management can be handled.

Maven won't download every time, only if the version you're dependent on isn't in your local repository.
 
Saloon Keeper
Posts: 22498
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

reubin haz wrote:
I think specify each jar with a <dependency> in the pom.xml is too long if there are many jars.... and I don't like to always download jars since I often encounter download failure.



You don't have to list each and every jar. If a jar is a dependency of another JAR you can omit it from the POM, since Maven will resolve sub-dependencies using the depending jar's POM from the repository.

In any event, as David said, your local repository serves as a cache, so JARs are only downloaded once per JAR version. If you run maven using the "-o" (offline) option, the network won't even be referenced at all, although you need an online build at least once to get the dependencies into your local cache.

The ability to do all of the above counts among Maven's major strengths, and additionally eliminates the need to manually replicate copies of jars throughout multiple projects.
 
reubin haz
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So could you tell me where to put other jar files in my 'local repository' or in my project, and how to specify in maven so maven know what I have already what not? I have tried to put them under /src/main/webapp/WEB-INF/lib/, and also tried to put in /WebContent/WEB-INF/lib/ then I specified in the pom I mentioned in my first posting. But they are not working.

I have spring-aop-2.0.8.jar, spring-beans-2.0.8.jar, spring-context-2.0.8.jar, ...., spring-web-2.0.8.jar, spring-webmvc-2.0.8.jar. There are 16 spring jars and a bunch of other jars. I could only guess dependency among jars by their names, like, spring-web-2.0.8.jar and spring-webmvc-2.0.8.jar. So its not easy to figure out which jars should be specified, which ones are not needed...

Thanks.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you should take a step back and read up on Maven--you might just be missing the point.

*You* don't put the jars anywhere--*Maven* does. You specify a dependency, say "spring" version "2.0.8". Maven downloads the jars and puts them in the repository. That's it. Maven handles the transitive dependencies--not you. If you know you're using a library, you can list it as a project dependency--but stop there; let Maven figure out the transitives.

When Maven packages the web app into a war your dependencies will be copied from the repo into your war.
 
No matter how many women are assigned to the project, a pregnancy takes nine months. Much longer than this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic