如何从Maven Central下载jar而不写任何pom.xml [重复]

时间:2022-01-29 12:02:21

This question already has an answer here:

这个问题在这里已有答案:

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.

我需要完成的唯一任务是下载罐子,我想有一个工具可以完成这项任务,不会给我带来超级信息。

There is something like that?

有类似的东西?

5 个解决方案

#1


47  

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 :

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依赖:get。这是这个问题的正确答案。

#2


15  

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。

#3


5  

Maven3 uses 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 Maven2 is 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:

使用参数工件将工件的名称设置为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

#4


1  

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

你应该看一下maven依赖插件,也许......尤其是它的go-offline mojo

#5


0  

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

看看常春藤吧。它允许从maven存储库中进行依赖性解析,而不会出现maven本身的过度复杂性。

#1


47  

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 :

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依赖:get。这是这个问题的正确答案。

#2


15  

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。

#3


5  

Maven3 uses 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 Maven2 is 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:

使用参数工件将工件的名称设置为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

#4


1  

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

你应该看一下maven依赖插件,也许......尤其是它的go-offline mojo

#5


0  

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

看看常春藤吧。它允许从maven存储库中进行依赖性解析,而不会出现maven本身的过度复杂性。