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
How to download jars from Maven Central without writing any pom.xml
提问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-dependencies
function.
如果要将 maven 依赖项下载到 lib 目录中,请使用具有该copy-dependencies
功能的依赖项插件。
mvn -DoutputDirectory=./lib -DincludeArtifactIds=commons-logging,commons-io dependency:copy-dependencies
Without the -DincludeArtifactIds
part 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 :
资源 :
- maven.apache.org - dependency:copy-dependencies
- force Maven2 to copy dependencies into target/lib
- maven.apache.org - dependency:get*see below**
On the same topic :
在同一主题上:
- Aggregate Dependencies in a Multi-Module Maven Project
- Set plugin's property on the command line in maven 2
- A simple command line to download a remote maven2 artifact to the local repository?*see below**
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
回答by Maxim Veksler
回答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 artifact
to 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 LATEST
to download the latest version of the artifact:
使用LATEST
下载最新版本的神器:
$ mvn dependency:get -DrepoUrl=http://download.java.net/maven/2/ \
-Dartifact=commons-io:commons-io:LATEST