简体   繁体   English

如何使用Maven pom将jar文件仅下载到特定目录?

[英]How to use Maven pom to download jar files only to a specific directory?

Is there a way to download dependencies from a pom.xml file to a specified folder in java? 有没有办法将pom.xml文件中的依赖项下载到java中的指定文件夹? I'm able to run maven command from java and I got download messages, but I don't know where maven stores these libraries? 我能够从java运行maven命令,我得到了下载消息,但我不知道maven在哪里存储这些库? How can I download these dependencies to a specific folder? 如何将这些依赖项下载到特定文件夹?

Take a look at maven's dependency plugin, specifically the copy-dependencies goal. 看一下maven的依赖插件,特别是copy-dependencies目标。 The usage section describes how to do exactly what you want. 用法部分描述了如何完全按照您的要求进行操作。

To do it from the command line just do: 要从命令行执行此操作,请执行以下操作:

$ mvn dependency:copy-dependencies -DoutputDirectory=OUTPUT_DIR

As explained here , you can use maven-dependency-plugin:get for this. 正如解释在这里 ,你可以使用Maven的依赖关系的插件:得到这个。

For example, if you want to download org.apache.hive:hive-common:2.1.1 in your local folder, execute this: 例如,如果要在本地文件夹中下载org.apache.hive:hive-common:2.1.1 ,请执行以下命令:

mvn dependency:get -Ddest=./ -Dartifact=org.apache.hive:hive-common:2.1.1

If you want to download the latest 3.0.0-SNAPSHOT:tar.gz version of com.orientechnologies:orientdb-community-gremlin from https://oss.sonatype.org/content/repositories/snapshots snapshots repository, execute this: 如果要从https://oss.sonatype.org/content/repositories/snapshots快照存储库下载最新的3.0.0-SNAPSHOT:tar.gz版本的com.orientechnologies:orientdb-community-gremlinhttps://oss.sonatype.org/content/repositories/snapshots执行以下命令:

mvn dependency:get -Ddest=./ -DremoteRepositories=sonatype-nexus-snapshots::::https://oss.sonatype.org/content/repositories/snapshots -Dartifact=com.orientechnologies:orientdb-community-gremlin:3.0.0-SNAPSHOT:tar.gz

Add something similar to the following to pom.xml: 在pom.xml中添加类似以下的内容:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <configuration>
        <outputDirectory>
            ${project.build.directory}
        </outputDirectory>
    </configuration>
</plugin>

Then run mvn clean dependency:copy-dependencies to perform the copy. 然后运行mvn clean dependency:copy-dependencies来执行复制。 Combine this with the assembly plugin and you can package everything into a self contained archive for distribution. 将它与程序集插件结合使用,您可以将所有内容打包到一个自包含的存档中进行分发。

  1. Go to this site: http://jar-download.com/online-maven-download-tool.php 访问此站点: http//jar-download.com/online-maven-download-tool.php

  2. Insert the Maven dependencies XML 插入Maven依赖项XML

  3. Download the jar files as a ZIP. 以ZIP格式下载jar文件。

Maven stores all of these in it's local Maven2 repository. Maven将所有这些存储在它的本地Maven2存储库中。 By default, it will store them in your user home directory under a directory called repository. 默认情况下,它会将它们存储在名为repository的目录下的用户主目录中。

You can use the maven-dependency-plugin's goal called copy to take all of your project's dependencies and put them in a folder. 您可以使用maven-dependency-plugin的目标称为copy来获取项目的所有依赖项并将它们放在一个文件夹中。

http://maven.apache.org/plugins/maven-dependency-plugin/copy-mojo.html http://maven.apache.org/plugins/maven-dependency-plugin/copy-mojo.html

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

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