本文介绍了maven 生成 pom 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 maven 3.0.3 并尝试为第三方 jar 生成 pom,如下所示:

I use maven 3.0.3 and have tried to generate pom for third-party jar like this:

mvn install:install-file -Dfile=cobra.jar -DgroupId=com.cobra-DartifactId=cobra -Dversion=0.98.4 -Dpackaging=jar -DgeneratePom=true

根据下面的链接,它应该生成正确的 pom.xml 并在 repo 中安装工件.http://maven.apache.org/plugins/maven-install-plugin/examples/generic-pom-generation.html

According to link below it should generate proper pom.xml and install artifact in the repo.http://maven.apache.org/plugins/maven-install-plugin/examples/generic-pom-generation.html

同时,它返回这样一个错误:

Meanwhile, it returns such a error:

[ERROR] 您指定的目标需要一个项目来执行,但有在此目录 (D:cobra-0.98.4lib) 中没有 POM.请验证您从正确的目录调用 Maven.-> [帮助 1]

为什么它应该生成 pom.xml 而要求 pom.xml?

Why is it asking for pom.xml while it should generate pom.xml?

推荐答案

这是一个老问题,但对我来说是几分钟的严重 PITA,所以我想我会分享:

This is an old question, but was a serious PITA for me for a few minutes, so I thought I'd share:

我刚刚遇到了这个问题,我认为这个问题可能与平台有关.真正的提示是 Cyril 的答案中的解决方案没有按预期工作:尽管我指定了 -DgroupId=com.xyz-DartifactId=whatever命令行和POM文件中的相应条目,jar安装在com/whatever下的本地repo中.

I just ran into this problem, and I believe that the issue is probably platform-dependent. The real tip-off was that the solution from Cyril's answer wasn't working as expected: despite my specification of -DgroupId=com.xyz and -DartifactId=whatever on the command-line and the corresponding entry in the POM file, the jar was installed in the local repo under com/whatever.

这让我尝试引用命令行参数,以及像这样格式化命令行的最终正确结果(删除 POM 文件后):

This led me to experiment with quoting command-line arguments, and the eventual correct result from formatting the command-line like this (after deleting the POM file):

mvn install:install-file "-Dfile=cobra.jar" "-DgroupId=com.cobra" "-DartifactId=cobra" "-Dversion=0.98.4" "-Dpackaging=jar" "-DgeneratePom=true"

有些引用无疑是多余的,但总比抱歉好,对吧?我碰巧在这台计算机上运行 Vista,如果这个问题特定于这个操作系统版本,我不会感到惊讶......顺便说一下,这是 Maven v3.0.4.

Some of the quoting is doubtless redundant, but better safe than sorry, right? I happen to be running Vista on this computer, and would not be surprised if this problem were specific to this OS version...by the way, this was with Maven v3.0.4.

这篇关于maven 生成 pom 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 20:01