简体   繁体   English

使用命令行从Nexus下载具有依赖性的Maven工件

[英]download of a Maven artifact with dependencies from Nexus using the command line

I'm using the command below to download a maven jar from Nexus through the command line. 我正在使用以下命令通过命令行从Nexus下载maven jar。

call mvn org.apache.maven.plugins:maven-dependency-plugin:2.4:get -DrepoUrl=http://10.101.15.190:8081/nexus/content/repositories/releases/ -Dartifact=bits:update-service:1.0.3 -Ddest=Setups/Services/update-service.jar

But what I get is a jar without dependencies. 但我得到的是一个没有依赖关系的jar。 There is already a jar with dependencies in Maven with the name update-service-1.0.4-jar-with-dependencies.jar Maven中已经有一个带有依赖项的jar,名称为update-service-1.0.4-jar-with-dependencies.jar

I tried the following: 我尝试了以下方法:

call mvn org.apache.maven.plugins:maven-dependency-plugin:2.4:get -DrepoUrl=http://10.101.15.190:8081/nexus/content/repositories/releases/ -Dartifact=bits:update-service:1.0.3[:packaging[:jar]] -Ddest=Setups/Services/update-service.jar

But it returns the following error: 但它返回以下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.4:get (default-cli) on project standalone-pom: Couldn't download artifact: Missing:
[ERROR] ----------
[ERROR] 1) bits:update-service:packaging[:jar]]:1.0.3[
[ERROR]
[ERROR] Try downloading the file manually from the project website.
[ERROR]
[ERROR] Then, install it using the command:
[ERROR] mvn install:install-file -DgroupId=bits -DartifactId=update-service -Dversion=1.0.3[ -Dclassifier=jar]] -Dpackaging=packaging[ -Dfile=/path/to/file
[ERROR]
[ERROR] Alternatively, if you host your own repository you can deploy the file there:
[ERROR] mvn deploy:deploy-file -DgroupId=bits -DartifactId=update-service -Dversion=1.0.3[ -Dclassifier=jar]] -Dpackaging=packaging[ -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
[ERROR]
[ERROR] Path to dependency:
[ERROR] 1) org.apache.maven.plugins:maven-downloader-plugin:jar:1.0
[ERROR] 2) bits:update-service:packaging[:jar]]:1.0.3[
[ERROR]
[ERROR] ----------
[ERROR] 1 required artifact is missing.
[ERROR]
[ERROR] for artifact:
[ERROR] org.apache.maven.plugins:maven-downloader-plugin:jar:1.0
[ERROR]
[ERROR] from the specified remote repositories:
[ERROR] central (https://repo.maven.apache.org/maven2, releases=true, snapshots=false),
[ERROR] temp (http://10.101.15.190:8081/nexus/content/repositories/releases/, releases=true, snapshots=true)
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Question : What is the correct way to download a jar with dependencies? 问题 :下载具有依赖项的jar的正确方法是什么?

jar-with-dependencies in this case is a Maven classifier : 在这种情况下, jar-with-dependencies是一个Maven classifier

The classifier allows to distinguish artifacts that were built from the same POM but differ in their content. 分类器允许区分从相同POM构建但其内容不同的工件。 It is some optional and arbitrary string that - if present - is appended to the artifact name just after the version number. 它是一些可选的任意字符串 - 如果存在 - 将附加到版本号之后的工件名称。

That is, the 1.0.4 jar and its with-dependencies variant differ in their Maven coordinates via the classifier. 也就是说, 1.0.4 jar及其with-dependencies变体通过分类器在Maven坐标上有所不同。

Hence, using the maven-dependency-plugin and its get goal you can specify a classifier via the classifier option: 因此,使用maven-dependency-plugin及其get目标,您可以通过classifier选项指定classifier classifier

The classifier of the artifact to download. 要下载的工件的分类器。 Ignored if artifact is used. 如果使用artifact则忽略。

However, you are indeed using the artifact option already, hence the option above will be ignored as per documentation. 但是,您确实已经使用了artifact选项,因此根据文档将忽略上面的选项。
If you look at the documentation of the artifact option though: 如果您查看artifact选项的文档,但:

A string of the form groupId:artifactId:version[:packaging][:classifier] . 形式为groupId:artifactId:version[:packaging][:classifier]的字符串。

Look at its last (optional) token, [:classifier] . 查看它的最后一个(可选)标记, [:classifier] This is exactly what you are missing. 这正是你所缺少的。

Your artifact option should be as following: 您的artifact选项应如下所示:

-Dartifact=bits:update-service:1.0.4:jar:jar-with-dependencies

Note: you actually already used it incorrectly when specifying: 注意:在指定时,您实际上已经错误地使用了它:

-Dartifact=bits:update-service:1.0.3[:packaging[:jar]]

The squared brackets [..] indicates optional parameters, you should not specify them in your command line invocation. 方括号[..]表示可选参数,不应在命令行调用中指定它们。 Moreover the packaging string there specify what value to put: again, you should not specify it, but just replace it with the corresponding value (in this case jar ). 此外, packaging字符串指定要放置的值:同样,您不应该指定它,而只需将其替换为相应的值(在本例中为jar )。

I have created an example to show you the way. 我已经创建了一个示例来向您展示方式。
I would like to download all the dependencies of spring-webmvc in version 4.2.5.RELEASE. 我想在4.2.5.RELEASE版本中下载spring-webmvc的所有依赖项。
1) You need the pom of webmvc if not already in your local repository. 1)如果尚未在本地存储库中,则需要webmvc的pom。 If spring-webmvc is already in the local repo then skip 1). 如果spring-webmvc已经在本地仓库中,则跳过1)。
2) You can download all the dependencies related to the pom your have just downloaded. 2)您可以下载与刚刚下载的pom相关的所有依赖项。

  1. downloading of the pom 下载pom

C:\\temp\\spring_web_mvc>mvn org.apache.maven.plugins:maven-dependency-plugin:2.10:get -DgroupId=org.springframework -DartifactId=spring-webmvc -Dversion=4.2.5.RELEASE -Dtype=pom C:\\ temp \\ spring_web_mvc> mvn org.apache.maven.plugins:maven-dependency-plugin:2.10:get -DgroupId = org.springframework -DartifactId = spring-webmvc -Dversion = 4.2.5.RELEASE -Dtype = pom

  1. downloading all the dependencies 下载所有依赖项

C:\\temp\\spring_web_mvc>mvn org.apache.maven.plugins:maven-dependency-plugin:2.10:copy-dependencies -f C:\\repository2\\org\\springframework\\spring-webmvc\\4.2.5.RELEASE\\spring-webmvc-4.2.5.RELEASE.pom -DoutputDirectory=C:\\TEMP C:\\ temp \\ spring_web_mvc> mvn org.apache.maven.plugins:maven-dependency-plugin:2.10:copy-dependencies -f C:\\ repository2 \\ org \\ springframework \\ spring-webmvc \\ 4.2.5.RELEASE \\ spring- webmvc-4.2.5.RELEASE.pom -DoutputDirectory = C:\\ TEMP

[INFO] Scanning for projects... [INFO]扫描项目......
[WARNING] Some problems were encountered while building the effective model for org.springframework:spring-webmvc:jar:4.2.5.RELEASE [警告]为org.springframework构建有效模型时遇到了一些问题:spring-webmvc:jar:4.2.5.RELEASE
... ...
[INFO] ------------------------------------------------------------------------ [INFO] ----------------------------------------------- -------------------------
[INFO] Building Spring Web MVC 4.2.5.RELEASE [INFO]构建Spring Web MVC 4.2.5.RELEASE
[INFO] ------------------------------------------------------------------------ [INFO] ----------------------------------------------- -------------------------
[WARNING] The POM for com.lowagie:itext:jar:2.1.7.js4 is missing, no dependency information available [警告] com.lowagie的pOM:itext:jar:2.1.7.js4缺失,没有可用的依赖项信息
[INFO] [信息]
[INFO] --- maven-dependency-plugin:2.10:copy-dependencies (default-cli) @ spring-webmvc --- [INFO] --- maven-dependency-plugin:2.10:copy-dependencies(default-cli)@ spring-webmvc ---
[WARNING] The POM for org.apache.maven.doxia:doxia-sink-api:jar:1.0 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details [警告] org.apache.maven.doxia的POM:doxia-sink-api:jar:1.0无效,传递依赖(如果有)将不可用,启用调试日志记录以获取更多详细信息
[INFO] org.apache.tiles:tiles-request-mustache:jar:1.0.6 already exists in destination. [INFO] org.apache.tiles:tiles-request-mustache:jar:1.0.6已存在于目标中。
[INFO] com.fasterxml.jackson.dataformat:jackson-dataformat-xml:jar:2.6.5 already exists in destination. [INFO] com.fasterxml.jackson.dataformat:jackson-dataformat-xml:jar:2.6.5已存在于目标中。
[INFO] org.apache.tiles:tiles-mvel:jar:3.0.5 already exists in destination. [INFO] org.apache.tiles:tiles-mvel:jar:3.0.5已存在于目标中。
[INFO] org.apache.tiles:tiles-jsp:jar:2.2.2 already exists in destination. [INFO] org.apache.tiles:tiles-jsp:jar:2.2.2已存在于目标中。
[INFO] org.jfree:jcommon:jar:1.0.23 already exists in destination. [INFO] org.jfree:jcommon:jar:1.0.23已存在于目标中。
... ...
[INFO] org.apache.tiles:tiles-extras:jar:3.0.5 already exists in destination. [INFO] org.apache.tiles:tiles-extras:jar:3.0.5已存在于目标中。
[INFO] ------------------------------------------------------------------------ [INFO] ----------------------------------------------- -------------------------
[INFO] BUILD SUCCESS [信息]建立成功
[INFO] ------------------------------------------------------------------------ [INFO] ----------------------------------------------- -------------------------
[INFO] Total time: 4.095 s [INFO]总时间:4.095秒
[INFO] Finished at: 2016-06-23T11:06:03+02:00 [INFO]完成于:2016-06-23T11:06:03 + 02:00
[INFO] Final Memory: 14M/241M [INFO]最终记忆:14M / 241M
[INFO] ------------------------------------------------------------------------ [INFO] ----------------------------------------------- -------------------------

Results: 结果:

C:\\temp\\spring_web_mvc>dir C:\\ TEMP \\ spring_web_mvc> DIR
Volume in drive C has no label. 驱动器C中的卷没有标签。
Volume Serial Number is F400-3CE5 卷序列号为F400-3CE5

Directory of C:\\temp\\spring_web_mvc C:\\ temp \\ spring_web_mvc目录

23/06/2016 11:05 . 2016/06/23 11:05
23/06/2016 11:05 .. 2016/06/23 11:05 ..
23/06/2016 10:24 4,467 aopalliance-1.0.jar 23/06/2016 10:24 4,467 aopalliance-1.0.jar
23/06/2016 10:24 192,035 bcmail-jdk14-1.38.jar 23/06/2016 10:24 192,035 bcmail-jdk14-1.38.jar
23/06/2016 10:24 192,035 bcmail-jdk14-138.jar ... 23/06/2016 10:24 192,035 bcmail-jdk14-138.jar ...

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

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