Java 如何在不编写任何 pom.xml 的情况下从 Maven Central 下载 jars

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3601570/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 02:31:08  来源:igfitidea点击:

How to download jars from Maven Central without writing any pom.xml

maven-2java

提问by Andrea Francia

I would like something like the following.

我想要类似以下的内容。

I want just an utility that is able to download jars and their dependencies from the Maven Repository without imposing no constraints on how my project should be built.

我只想要一个实用程序,它能够从 Maven 存储库下载 jar 及其依赖项,而不会对我的项目的构建方式施加任何限制。

I would like something like this:

我想要这样的东西:

download-jar --dest=lib/ 'commons-io:commons-io:jar:1.4'

It should be able to download also the dependencies.

它也应该能够下载依赖项。

Update:

更新:

I wouldn't know about a pom.xml should be structured.

我不知道 pom.xml 应该是结构化的。

The only task I need to be accomplished is the download of the jars, I would like have a tool that could accomplish this task that doesn't bother me with superflous information.

我需要完成的唯一任务是下载 jars,我想要一个工具来完成这个任务,而不会用多余的信息来打扰我。

There is something like that?

有这样的事情吗?

采纳答案by Colin Hebert

If you want to download maven dependencies into your lib directory use the dependency plugin with the copy-dependenciesfunction.

如果要将 maven 依赖项下载到 lib 目录中,请使用具有该copy-dependencies功能的依赖项插件。

mvn -DoutputDirectory=./lib -DincludeArtifactIds=commons-logging,commons-io dependency:copy-dependencies 

Without the -DincludeArtifactIdspart you'll download every dependency.

如果没有该-DincludeArtifactIds部分,您将下载每个依赖项。

If you want to download a an artifact without having a specific project *see below** :

如果您想在没有特定项目的情况下下载工件 *请参见下文**:

mvn -DgroupId=commons-io -DartifactId=commons-io -Dversion=1.4 dependency:get


Resources :

资源 :

On the same topic :

在同一主题上:

Interesting comments :

有趣的评论:

  • *@Pascal Thivent :

    No need to setup a POM, no need to develop your own tool, use mvn dependency:get. That's the right answer to this question.

  • *@帕斯卡·蒂文特:

    无需设置POM,无需开发自己的工具,使用mvn dependency:get。这是这个问题的正确答案。

回答by Riduidel

You should take a look at the maven dependency plugin, maybe ... and especially its go-offlinemojo

你应该看看maven依赖插件,也许......尤其是它的离线mojo

回答by Maxim Veksler

Have a look at Ivy. It allows dependency resolution from maven repositories without the overkill complexity of maven itself.

看看常春藤。它允许从 Maven 存储库中解析依赖项,而没有 Maven 本身的过度复杂性。

回答by chbrown

I also had to specify -DrepoUrl, after getting the error message:

-DrepoUrl收到错误消息后,我还必须指定:

Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.1:get 
  (default-cli) on project standalone-pom: The parameters 'repositoryUrl' 
  for goal org.apache.maven.plugins:maven-dependency-plugin:2.1:get are 
  missing or invalid -> [Help 1]

So here is the command I used:

所以这是我使用的命令:

mvn -DgroupId=edu.umd -DartifactId=cloud9 -Dversion=1.3.5 \
  -DrepoUrl="http://repo1.maven.org/maven2" dependency:get

Furthemore, -Ddest=~didn't work. It always insisted on installing the jar to ~/.m2/repository.

此外,-Ddest=~没有奏效。它始终坚持将 jar 安装到~/.m2/repository.

回答by Diego Pino

Maven3uses dependency plugin v2.1 by default:

Maven3默认使用依赖插件 v2.1:

$ mvn dependency:get -DrepoUrl=http://download.java.net/maven/2/ \
   -DgroupId=commons-io -DartifactId=commons-io -Dversion=1.4

With Maven2is still necessary to write the canonical name:

使用Maven2仍然需要编写规范名称:

$ mvn2 org.apache.maven.plugins:maven-dependency-plugin:2.1:get \
   -DrepoUrl=http://download.java.net/maven/2/ \
   -DgroupId=commons-io -DartifactId=commons-io -Dversion=1.4

Use parameter artifactto set the name of the artifact as group:artifact:version:

使用参数artifact将工件的名称设置为group:artifact:version

$ mvn dependency:get -DrepoUrl=http://download.java.net/maven/2/ \
   -Dartifact=commons-io:commons-io:1.4

Use LATESTto download the latest version of the artifact:

使用LATEST下载最新版本的神器:

$ mvn dependency:get -DrepoUrl=http://download.java.net/maven/2/ \
   -Dartifact=commons-io:commons-io:LATEST