开发者

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

This question already has answers here: A simple command line to download a remote maven2 artifact to the local repository? (3 answers) Closed 9 years ago.

I would like somethi开发者_C百科ng 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.

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.

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?


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

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

Without the -DincludeArtifactIds part you'll download every dependency.

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.


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

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.


Maven3 uses dependency plugin v2.1 by default:

$ 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:

$ 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:

$ 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:

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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜