2011-07-15 51 views
27

我用maven 3.0.3,並嘗試生成的第三方jar像這樣POM:行家產生POM文件

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

根據鏈接下方應該產生適當的pom.xml,並在安裝神器回購。 http://maven.apache.org/plugins/maven-install-plugin/examples/generic-pom-generation.html

同時,它會返回這樣的錯誤:

[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (D:\cobra-0.98.4\lib). Please verify you invoked Maven from the correct directory. -> [Help 1]

爲什麼要求pom.xml的,而應該產生的pom.xml?

+0

我只是在Windows 7的cmd上運行這一行,它適用於Maven 3.0.5。也許他們修正了這個版本。 – firen

回答

67

這是一個老問題,但對我來說是一個嚴重的PITA了幾分鐘,所以我想我會分享:

我只是碰到了這個問題,我相信這個問題可能與平臺有關。真正的提示是Cyril答案的解決方案沒有按預期工作:儘管我在命令行上的-DgroupId=com.xyz-DartifactId=whatever的規範以及POM文件中的相應條目,但是該jar被安裝在本地倉庫中,位於com/whatever

這使我使用引號命令行參數,並從格式化命令行這樣最終正確的結果(刪除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。

+7

什麼是垃圾錯誤消息「您指定的目標需要項目執行...」是。 –

+5

+1。這在使用控制檯時適用於我。 CMD按預期工作,沒有引用。 – flesk

+0

與flesk寫的相似,對於Windows,我在powershell中得到這個錯誤,而不是在cmd中,謝謝flesk –

8

您確定您正在執行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' 
+0

沒有這樣的錯字。你能告訴你使用的Maven版本嗎? – firen

+0

@firen查看我的回答更新。 – FrVaBe

+0

我有完全相同的版本......不知道真的,也許我會調試Maven代碼,看看發生了什麼。 – firen

3

我發現了一個旁路。你需要像這樣創建一個簡單的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 
... 
1

嘗試在cmd上運行它。exe或執行cmd命令之前mvn命令

+0

我有同樣的問題,這將解決。 – Sin2

0

只是在你的項目目錄下,你可以找到你的pom.xml文件,然後執行相同的命令!它適用於我;)

0

如果您在命令行版本的Maven遇到問題,您可能需要嘗試用於eclipse的M2E插件。對於Maven經驗不多的人來說,它更加用戶友好。

0

當我將Powershell更改爲Cygwin時,它適用於我。 Powershell以某種方式錯誤地解析命令行參數。