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.
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.
Normally you don't need to list all the dependencies in the project that imports your library. Maven should fetch them for you. What you need to do is to declare dependencies in your library.
Make sure you declare correct types of dependencies. Here is more info. In your case you need to make sure that dependencies you want to copy to the downstream projects are marked as 'compile'
There are tools that make 'Fat' jars by copying all dependencies inside. But they are mostly used to build the final project such as a deployable WAR file or a desktop app. Not in case of the libraries
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With