GeeCON Prague 2014*
The moose likes Ant, Maven and Other Build Tools and the fly likes How to put jar after creating it in war file's lib through Maven 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 to put jar after creating it in war file Watch "How to put jar after creating it in war file New topic
Author

How to put jar after creating it in war file's lib through Maven

Kousik Majumder
Ranch Hand

Joined: Sep 30, 2007
Posts: 229
Hi all,

I want to create a .war file in maven. in the war file's lib directory I need to put some jar files too(which I have to create at the time of creating war).

How can I do that through maven.Pease give an example.



Thanks in Advance,
Kousik
Praneet Mirchandani
Ranch Hand

Joined: Dec 16, 2009
Posts: 46

Hi

From what I understood, you would need to specify packaging type in your pom.xml.

<project>
.......
<packaging>war</packaging>
....
</project>

This would make a war file of your project.

I am not too sure how to add jar files to this war.

What you can do is install any jars you need on your local repsitory using:
mvn install:install-file -DgroupId=ojdbc -DartifactId=ojdbc -Dversion=14 -Dpackaging=jar -Dfile=D:\ojdbc14.jar

This installs the ojdbc14.jar file located in the D drive on your local repository.

Hope this helps.

Praneet


Thanks,
Praneet
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

The WAR task will populate the WEB-INF/lib with the dependent libraries.
Kousik Majumder
Ranch Hand

Joined: Sep 30, 2007
Posts: 229

Actually I dont have any jar files so far which I can add in WAR task.
When this war file will be created then the jar files will also be created. I want to know how can I create those jar files and put those into the war file altogether.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What's your use case for that? In other words, why bother?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16095
    
  21

You need to create a Maven project for each of the jar files that you're creating. Each of those Maven projects will create its corresponding JAR. Build the JARs using the "mvn install" goal for each jar.

Construct dependency elements in the WAR file. Once dependency element for each constructed JAR. Then when you build the WAR, Maven will retrieve the installed jars and place them in the WAR - assuming you used one of the dependency scopes that copies. Which is practically any scope except "provided".

Ant can produce multiple artifacts from a single build.xml, but Maven is different. Each POM is intended to produce one and only one artifact. You can define a master POM with dependent POMs for each of the JARS and the WAR, but no one single POM can produce multiple artifacts.


Customer surveys are for companies who didn't pay proper attention to begin with.
Kousik Majumder
Ranch Hand

Joined: Sep 30, 2007
Posts: 229

Thank you Tim. Your explanation cleared my concept.
Thank you again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to put jar after creating it in war file's lib through Maven