繁体   English   中英

maven 生成pom文件

[英]maven generating pom file

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

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

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

[错误] 您指定的目标需要执行项目,但此目录 (D:\cobra-0.98.4\lib) 中没有 POM。 请确认您从正确的目录调用了 Maven。 -> [帮助 1]

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

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

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

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

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。

你确定你正在执行install-file目标吗? 我检查了你的命令,它对我有用,但是当我放置一个空白的install:install-file (也许你有这个错字)时,将使用install目标,它需要一个 pom.xml。

尝试使用-X参数获取更多调试信息:

 -X,--debug       Produce execution debug output

我的系统

Maven

c:\>mvn -version

Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
Maven home: C:\progs\apache-maven-3.0.3
Java version: 1.6.0_21, vendor: Sun Microsystems Inc.
Java home: c:\Program Files (x86)\Java\jdk1.6.0_21\jre
Default locale: de_DE, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"

安装插件

c:\>mvn -Dplugin=install help:describe

Name: Maven Install Plugin
Description: Copies the project artifacts to the user's local repository.
Group Id: org.apache.maven.plugins
Artifact Id: maven-install-plugin
Version: 2.3.1
Goal Prefix: install

This plugin has 3 goals:

install:help
  Description: Display help information on maven-install-plugin.
    Call
      mvn install:help -Ddetail=true -Dgoal=<goal-name>
    to display parameter details.

install:install
  Description: Installs the project's main artifact in the local repository.

install:install-file
  Description: Installs a file in the local repository.

For more information, run 'mvn help:describe [...] -Ddetail'

我找到了一个旁路。 您需要像这样创建一个简单的 pom.xml:

<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.cobra</groupId>
    <artifactId>cobra</artifactId>
    <version>0.98.4</version>
</project>

它并不完美,但它对我有用。 如果您找到更好的方法来做到这一点,我很感兴趣。

我的配置:

$mvn -version
Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
Maven home: /usr/local/maven
Java version: 1.6.0_20, vendor: Sun Microsystems Inc.
Java home: /usr/local/jdk1.6.0_20/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-25-generic-pae", arch: "i386", family: "unix"

$mvn -Dplugin=install help:describe
...
Name: Maven Install Plugin
Description: Copies the project artifacts to the user's local repository.
Group Id: org.apache.maven.plugins
Artifact Id: maven-install-plugin
Version: 2.3.1
Goal Prefix: install
...

尝试在cmd.exe上运行它或在mvn命令之前执行cmd命令。

只是 go 在您的项目目录下,您可以在其中找到您的 pom.xml 文件,然后执行相同的命令; 这个对我有用 ;)

如果您在使用 Maven 的命令行版本时遇到问题,您可能想尝试 eclipse 的 M2E 插件。 对于没有太多 Maven 经验的人来说,它的用户友好性要高得多。

当我将 Powershell 更改为 Cygwin 时,它对我有用。 Powershell 以某种方式错误地解析了命令行参数。

当我在 Windows 中使用 maven 时,我遇到了这个错误,对我有用的是打开 cmd 而不是 Z3D265B8FA888CDF03。 显然,当您不使用 cmd 时会出现某些错误。 我希望它有效。

使用 maven 版本 3.6.3,这对我在我选择的目录中生成 pom 文件很有用:

C:mvn 原型:生成“-DgroupId=com.mycompany.app”“-DartifactId=my-app”“-DarchetypeArtifactId=maven-archetype-quickstart”“-DarchetypeVersion=1.4”“-DinteractiveMode=false”

If you are getting this error during jenkins pipeline setup, Then the error is we are placing git repository without.git in jenkins git url blank.Generally we put website url of git repo but we need to place clone url of git repo.Insert. git(克隆网址)到网站url,只需插入git克隆Z572D4E421E5E8A06B9BC12Z81。

暂无
暂无

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

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