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.
The problem with
systemPath
is that the dependencies' jars won't get distributed along your artifacts as transitive dependencies. Try what I've posted here: Is it best to Mavenize your project jar files or put them in WEB-INF/lib?Then declare dependencies as usual.
And please read the footer note.
To install the 3rd party jar which is not in maven repository use maven-install-plugin.
Below are steps:
Below is the e.g one I used it for simonsite log4j
In the pom.xml include the dependency as below
Run the mvn clean install command to create your packaging
Below is the reference link:
https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
This is what I have done, it also works around the package issue and it works with checked out code.
I created a new folder in the project in my case I used
repo
, but feel free to usesrc/repo
In my POM I had a dependency that is not in any public maven repositories
I then created the following directories
repo/com/dovetail/zoslog4j/1.0.1
and copied the JAR file into that folder.I created the following POM file to represent the downloaded file (this step is optional, but it removes a WARNING) and helps the next guy figure out where I got the file to begin with.
Two optional files I create are the SHA1 checksums for the POM and the JAR to remove the missing checksum warnings.
Finally I add the following fragment to my pom.xml that allows me to refer to the local repository
If you want a quick and dirty solution, you can do the following (though I do not recommend this for anything except test projects, maven will complain in length that this is not proper).
Add a dependency entry for each jar file you need, preferably with a perl script or something similar and copy/paste that into your pom file.
What works in our project is what Archimedes Trajano wrote, but we had in our .m2/settings.xml something like this:
and the * should be changed to central. So if his answer doesn't work for you, you should check your settings.xml
I just wanted a quick and dirty workaround... I couldn't run the script from Nikita Volkov: syntax error + it requires a strict format for the jar names.
I made this Perl script which works with whatever format for the jar file names, and it generates the dependencies in an xml so it can be copy pasted directly in a pom.
If you want to use it, make sure you understand what the script is doing, you may need to change the
lib
folder and the value for thegroupId
orartifactId
...