Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Kousik Majumder
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
Praneet Mirchandani
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The WAR task will populate the WEB-INF/lib with the dependent libraries.
 
Kousik Majumder
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's your use case for that? In other words, why bother?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18154
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kousik Majumder
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thank you Tim. Your explanation cleared my concept.
Thank you again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic