简体   繁体   English

安装具有第三方非mvn jar依赖项的第三方非mvn jar

[英]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, ...". 我有一个maven repo中不存在的第三方jar,我们称之为“a.jar”,这也取决于至少20多个第三方罐子,其中大部分都不在maven中,让我们称他们为“b.jar,c.jar,d.jar,......”。 How do I properly install it into the mvn repo with all it's dependencies? 如何正确地将它安装到具有所有依赖关系的mvn repo中?

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? 我认为标准的“ mvn install:install-file ”在这种情况下不会起作用,因为我会将“a.jar”安装到repo中,但它的依赖关系都没有,对吧? Plus, how would mvn even know that "a.jar" has dependencies when it's used in other projects. 另外,当它在其他项目中使用时,mvn甚至会知道“a.jar”具有依赖性。

I've seen one other stackoverflow question that seems similar to what I'm trying to do, 我见过另一个与我正在尝试的类似的stackoverflow问题,

maven install and deploy 3rd party dependencies with simple command line maven使用简单的命令行安装和部署第三方依赖项

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! 但我是一个mvn noob并且它没有足够的解释所以我大部分都失去了他正在做的事情和原因:(。我的意思是我不明白为什么我需要包含pom.xml父文件和子文件将这些依赖项安装到mvn repo中...我现在拥有的是一个包含大量jar的lib文件夹!

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. 尽管Maven让我们的生活变得更轻松,但您已经设法找到一个实际上让我们的生活变得更加困难的领域,至少在最初阶段。 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. 一旦图书馆在回购中,Maven的依赖机制就很棒,生活也值得生存。 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. 要做的是将你的库放在一个仓库中,以便maven可以使用它。 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. ArtifactoryNexus都是maven存储库管理器,你应该考虑运行其中一个,这样你就可以从maven构建和第三方库中部署工件了。 I use Artifactory and like it very much, but I hear Nexus is very good as well and is written by the Sonatype guys. 我使用Artifactory非常喜欢它,但我听说Nexus非常好,并且是由Sonatype人写的。 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. 这些repo充当中央仓库的代理,您可以将maven构建专门指向它们,并从中央仓库解析并下载工件并缓存它们。 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). 由于缺少网络上的存储库,您始终可以将工件部署/安装到您的盒子上的本地存储库(位于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. 当您在本地盒子上运行maven构建并告诉maven“安装”时,这就是放置构建工件的地方。 Also, any dependencies maven downloads from the central repo during a build is placed here and reused during later builds, to reduce network traffic. 此外,在构建期间从中央存储库下载的任何依赖项maven下载并在以后的构建期间重用,以减少网络流量。 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. 因此,推荐的方法是为所有开发人员都可以使用的所有工件创建一个公司maven repo。

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. 您可以使用默认poms部署第三方库及其所有依赖项,然后在项目pom文件中将它们全部声明为依赖项。 Or, you can rely on maven's transitive dependency mechanism. 或者,您可以依赖maven的传递依赖机制。 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. 您将首先使用pom文件部署第三方库,该文件声明其所有依赖项...然后将所有依赖项部署为使用默认poms。 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. 最后,在你的项目pom中你可以声明对第三方库的依赖,并通过maven的传递依赖机制maven将获取所有其他库。

I recommend you spend some time reading through the online Sontatype books including "Maven: The Complete Reference" and "Repository Management with Nexus" . 我建议您花一些时间阅读在线Sontatype书籍,包括“Maven:完整参考”“使用Nexus进行存储库管理”

When you do a mvn install:install-file you can specify a pom file for what you are installing. 当您执行mvn install:install-file时,您可以为要安装的内容指定一个pom文件。 Just put your dependencies in that pom. 把你的依赖放在那个pom中。

Edit: Oh and then do it for the dependencies as well. 编辑:哦,然后为依赖项做这件事。 Probably easier to do it for the dependencies first. 首先可能更容易为依赖项执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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