Search code examples
javamavenmaven-dependency

Export maven as jar file with all dependencies


I have my own java library created as maven project and has some dependencies included in pom.xml

I want to export project as jar and include it into others maven projects.

The problem is that I need to copy all dependencies from pom.xml of my library into maven projects where is imported my library to make it to work.

How to export my library to not be necessary to copy dependencies of my library.


Solution

  • That is easy to do; the central feature of Maven is that it manages the project dependencies for you.

    You need to mvn install your project from the command line; that will install the jar and the pom files to your local repository.

    You can then include your library as a Maven dependency in other Maven based projects; Maven will resolve the (transitive) dependencies for your project.