This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Ant, Maven and Other Build Tools and the fly likes How to include optional jars in Maven while building WAR Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "How to include optional jars in Maven while building WAR" Watch "How to include optional jars in Maven while building WAR" New topic
Author

How to include optional jars in Maven while building WAR

tanu dua
Ranch Hand

Joined: Apr 05, 2004
Posts: 145
Hi,

I need to make a war file of my project who is dependent on the spring . I have referred the dependency as

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
</dependency>

The outcome i get is that in the lib folder of war file , I get two jars commons-logging.jar and spring-core.jar . I saw the pom.xml of spring-core module and it has also the dependency of commons-collections but that jar is not imported and included in my war file as <optional>true</optional> has bee set in spring-core pom.xml .

Is there any way to include all the jars whether optional , provided , test etc while building war
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5838
    
    7

As far as I know, the only way to include it is to add it as a dependency in your POM and not mark it optional.

See this doc: http://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html
Here is a quote from that page:
MavenDocs wrote:If a user wants to use functionality related to an optional dependency, they will have to redeclare that optional dependency in their own project.


JBoss In Action
tanu dua
Ranch Hand

Joined: Apr 05, 2004
Posts: 145
But that just I want to avoid it though I am not sure how. To give you more context our project currently is on spring2.2.5 version and we don't use maven . We need to upgrade now our version from spring2.2.5 to spring 3.0.5.RELEASE . I searched through the net to know the dependency jars which this spring version would depen upon and could not find that . Instead I got the following thread in spring forum which says that you should use maven to get the dependent jars.

http://forum.springsource.org/showthread.php?t=103862

Now , since we can't upgrade to maven framework right away , I though to get the dependency jars by referring spring artifact assuming that all the dependencies jars would also come with it . But the optional one is left out.

Following is the link I refer to refer the spring artifacts in my pom.xml

http://blog.springsource.com/2009/12/02/obtaining-spring-3-artifacts-with-maven/

Is there any way to get them also else I need to go into each pom.xml of spring and copy the optional dependency from there and paste it into mine.

Thanks
Tanu

Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5838
    
    7

Oh, so you are not using Maven to build your project, you are just trying to gather all of the dependent JARs. There might be hope! Try using either the Maven Assembly Plugin or the Maven Dependency Plugin. Both of those will gather transitive dependencies, and they are both highly configurable, and perhaps one of them will do what you need.
 
 
subject: How to include optional jars in Maven while building WAR