Maven2 is driving me crazy during the experimentation / quick and dirty mock-up phase of development.
I have a pom.xml
file that defines the dependencies for the web-app framework I want to use, and I can quickly generate starter projects from that file. However, sometimes I want to link to a 3rd party library that doesn't already have a pom.xml
file defined, so rather than create the pom.xml
file for the 3rd party lib by hand and install it, and add the dependency to my pom.xml
, I would just like to tell Maven: "In addition to my defined dependencies, include any jars that are in /lib
too."
It seems like this ought to be simple, but if it is, I am missing something.
Any pointers on how to do this are greatly appreciated. Short of that, if there is a simple way to point maven to a /lib
directory and easily create a pom.xml
with all the enclosed jars mapped to a single dependency which I could then name / install and link to in one fell swoop would also suffice.
A quick&dirty batch solution (based on Alex's answer):
libs.bat
Execute it like this:
libs.bat > libs.txt
. Then openlibs.txt
and copy its content as dependencies.In my case, I only needed the libraries to compile my code, and this solution was the best for that purpose.
You may create local repository on your project
For example if you have
libs
folder in project structureIn
libs
folder you should create directory structure like:/groupId/artifactId/version/artifactId-version.jar
In your pom.xml you should register repository
and add dependency as usual
That is all.
For detailed information: How to add external libraries in Maven
For those that didn't find a good answer here, this is what we are doing to get a jar with all the necessary dependencies in it. This answer (https://stackoverflow.com/a/7623805/1084306) mentions to use the Maven Assembly plugin but doesn't actually give an example in the answer. And if you don't read all the way to the end of the answer (it's pretty lengthy), you may miss it. Adding the below to your pom.xml will generate
target/${PROJECT_NAME}-${VERSION}-jar-with-dependencies.jar
Even though it does not exactly fit to your problem, I'll drop this here. My requirements were:
Let's talk about (3) first: Just having the jars in a folder and somehow merging them into the final jar will not work for here, since the IDE will not understand this. This means all libraries have to be installed properly. However, I dont want to have everyone installing it using "mvn install-file".
In my project I needed metawidget. Here we go:
Every time you have a new library, just add a new execution and tell everyone to build the project again (you can improve this process with project hierachies).
For throw away code only
set scope == system and just make up a groupId, artifactId, and version
Note: system dependencies are not copied into resulted jar/war
(see How to include system dependencies in war built using maven)
What seems simplest to me is just configure your maven-compiler-plugin to include your custom jars. This example will load any jar files in a lib directory.