简体   繁体   中英

Install a 3rd-party non-mvn jar that has 3rd-party non-mvn jar dependencies

I have a third-party jar that doesn't exist in the maven repo, let's call it "a.jar", that also depends on at least 20+ third-party jars, most of which aren't in maven either, let's call them "b.jar, c.jar, d.jar, ...". How do I properly install it into the mvn repo with all it's dependencies?

I don't think the standard " mvn install:install-file " would work in this situation because I would install "a.jar" into the repo but none of its dependencies would be there, right? Plus, how would mvn even know that "a.jar" has dependencies when it's used in other projects.

I've seen one other stackoverflow question that seems similar to what I'm trying to do,

maven install and deploy 3rd party dependencies with simple command line

But I'm a mvn noob and it doesn't explain enough so I'm mostly lost on what he's doing and why : (. I mean I don't understand why I'd need to include pom.xml parent and child files to install these dependencies into the mvn repo... All I have right now is a lib folder with a whole bunch of jars in it!

For all that Maven makes our lives easier you have have managed to find an area that it actually makes our lives harder, at least initially. It can be a right pain to get missing libraries in a repository where you can use them, especially for newbies. Once a library is in a repo Maven's dependency mechanism is great and life is worth living. In the long run it saves you a great amount of time and headache. But first you have to suffer...

The thing to do is to get your library in a repo so maven can use it. First, I would look really hard at the central repo and make sure the library(s) you are after is not there already. You can search the central repo for your library.

If you must deploy it to a repo the first thing you should know is that most people host their own repositories within their corporate or private network. Artifactory and Nexus are both maven repository managers and you should look into running one of these so you have somewhere to deploy the artifacts from your maven builds as well and 3rd party libraries. I use Artifactory and like it very much, but I hear Nexus is very good as well and is written by the Sonatype guys. These repo's act as a proxy for the central repo where you point your maven builds to them exclusively and they resolve and download artifacts from the central repos and cache them. The central repo's love this because they are swamped by network traffic as it is.

Lacking a repo on your network you can always deploy/install artifacts to your local repo on your box (located in userhome.m2\\repository). When you run a maven build on your local box and tell maven to "install" then this is where puts your build artifacts. Also, any dependencies maven downloads from the central repo during a build is placed here and reused during later builds, to reduce network traffic. The down side is that if you work with other developers they can't just checkout and build your code... they have to go through frustrating and error prone steps to deploy artifacts to their local repo. So the recommended way is to have a corporate maven repo for all your artifacts that all your developers can use.

All that aside, there is two general strategies you can follow for your immediate problem. You can deploy the 3rd party library and all its dependencies using default poms and then in your project pom file declare them all as dependencies. Or, you can rely on maven's transitive dependency mechanism. You would first deploy the 3rd party library with a pom file that declares all of its dependencies... then deploy all of its dependencies as using default poms for them. Lastly, in your project pom you can just declare a dependency on the 3rd party library and through maven's transitive dependency mechanism maven will grab all the other libraries.

I recommend you spend some time reading through the online Sontatype books including "Maven: The Complete Reference" and "Repository Management with Nexus" .

When you do a mvn install:install-file you can specify a pom file for what you are installing. Just put your dependencies in that pom.

Edit: Oh and then do it for the dependencies as well. Probably easier to do it for the dependencies first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM