0

I have two maven projects, the second project extends some classes of first project. I want to create the jar file with all dependencies of first project and include it to another project as dependency. I am searching this since long time, is it possible to do it?

I am new to maven, any help on this would be highly appreciated.

Thanks

Arsalan
  • 15
  • 1
  • 7

4 Answers4

0

If I understand you right, you want to create a uber-jar containing all dependencies, right ?

Please refer to this question How can I create an executable JAR with dependencies using Maven?

Community
  • 1
  • 1
Olivier Refalo
  • 50,287
  • 22
  • 91
  • 122
  • Thanks Olovier, I have created jar with dependencies, now i want to include as a dependency in another maven project (in pom file), so that it would be picked up from my local .m2 folder. – Arsalan Feb 28 '12 at 16:39
0

If you just want to add the dependencies to another project you add the second project dependency to your new project and the first one will be inherited and automatically included. This is what is called a transitive dependency. Read more about it in the free book Maven: The Complete Reference.

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
0

In the second project's POM file, specify the first projects maven co-ordinates (groupId,artifactId,version,packaging) under the 'dependency' section. It will transitively acquire all the dependent artifacts.

Although it is possible in Maven to generate a standalone jar with all its dependencies. For that purpose, you can use the maven-shade-plugin. ( Reference )

appu
  • 538
  • 10
  • 24
0

There are two ways you are create a fat jar. You include the jar itself in the jar of dependent. You will not have much control in this case and the maven assembly plugin would do the work. Alternatively, you can unzip the jar and zip everything together to create the new jar. You have to decide which one best suits you. If you have multiple versions of same class, then include the whole jar in the new jar would help, but if the versions are coherent, it's best to create a jar by unzipping and zipping everything. For the second procedure, I recommend using the maven shade plugin to create uber jar.

Ozyman
  • 503
  • 1
  • 6
  • 16