简体   繁体   English

如何将工件和所有依赖项递归下载到目录中?

[英]How can I recursively download an artifact and all dependencies into a directory?

I don't have an internet connection at work, and I want to bring there a specific library.我在工作时没有互联网连接,我想带一个特定的图书馆。

So I want to be able to download at home an artifact along with all of its dependencies (recursively), in order to be able to take all of these jars and bring them to work.因此,我希望能够在家中下载工件及其所有依赖项(递归),以便能够获取所有这些 jar 并将它们用于工作。

I have read on this site about dependency:get , which is great but downloads the artifacts to the local Maven repo ( ~/.m2/repository ).我在这个网站上阅读了关于dependency:get ,这很棒,但将工件下载到本地 Maven ~/.m2/repository ( ~/.m2/repository )。 This means that after downloading, I need to look at pom files and manually copy all of the dependent JAR files to some directory, which I can then bring to work.这意味着下载后,我需要查看pom文件并手动将所有依赖的 JAR 文件复制到某个目录,然后我可以将其用于工作。

I would love to have a way to simply download the desired JAR and all of its dependencies into a specific folder.我希望有一种方法可以将所需的 JAR 及其所有依赖项简单地下载到特定文件夹中。

Is there a way to acheive this?有没有办法实现这一目标?

Please note: this question is different than the mentioned duplicate, in that I'm asking how to do this without any project or pom.xml file.请注意:这个问题与提到的重复问题不同,因为我问的是如何在没有任何项目或pom.xml文件的情况下做到这一点。 I'm looking for the simplest way to do this.我正在寻找最简单的方法来做到这一点。

EDIT : I believe I found a possible solution (not the most elegant though..):编辑:我相信我找到了一个可能的解决方案(虽然不是最优雅的......):

  1. Rename the local repo ( ~\\.m2\\repository on my Windows machine) to repository.old .将本地~\\.m2\\repository (我的 Windows 机器上的~\\.m2\\repository )重命名为repository.old Create an empty directory repository at the same location instead.改为在同一位置创建一个空目录repository

  2. Run

    mvn dependency:get -Dartifact=<groupid>:<artifactid>:<version>

    This doesn't require a pom.xml or a project.这不需要pom.xml或项目。

  3. The artifact and dependencies have been downloaded to your local previously-empty repository ( ~\\.m2\\repository ).工件和依赖项已下载到您本地以前为空的存储库 ( ~\\.m2\\repository )。

  4. Move the local repository to wherever, and rename repository.old back to repository .将本地存储库移动到任何位置,并将repository.old重命名回repository

(I think) you now have all the dependencies for your desired artifact. (我认为)您现在拥有所需工件的所有依赖项。

dependency:get will load everything you need in .m2 then when you are offline you will be good. dependency:get将在.m2加载您需要的所有内容,然后当您离线时,您会很好。 I don't think you need to do anything else.我不认为你需要做任何其他事情。

Test it by disconnecting your machine for your network when you are at home.当您在家时,通过断开网络连接来测试它。

Normally the dependencies are downloaded when maven is updating the indieces.通常在 maven 更新索引时下载依赖项。 As you can see in this post: What is Eclipse doing when it says that it's updating indexes?正如您在这篇文章中看到的: 当 Eclipse 说它正在更新索引时,它在做什么? you just need to enable eclipse or whatever ide youre using to download the sources as well.您只需要启用 eclipse 或您用来下载源代码的任何 ide。

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

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