2014-10-08 82 views
4

我按照指南here將JAR文件安裝到我的本地存儲庫中。當安裝JAR到版本庫時,Maven不會讀取POM

我運行以下命令:

mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=log4j-weblayout-0.0.1-SNAPSHOT.jar 

JAR文件使用Maven構建,幷包含在它裏面列出其依賴關係的POM文件。 JAR中的文件有以下路徑:

/META-INF/maven/in.ksharma/log4j-weblayout/pom.xml 

Maven安裝了工件,但未讀取其POM。它創建一個空的POM文件這是任何依賴信息無效:

<?xml version="1.0" encoding="UTF-8"?> 
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>in.ksharma</groupId> 
    <artifactId>log4j-weblayout</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <description>POM was created from install:install-file</description> 
</project> 

我怎樣才能確保JAR裏面的POM是安裝的一個?

編輯:

的JAR內部的各種文件的內容如下。

/META-INF/MANIFEST.MF

Manifest-Version: 1.0 
Archiver-Version: Plexus Archiver 
Built-By: kshitiz 
Created-By: Apache Maven 3.1.0 
Build-Jdk: 1.8.0 

/META-INF/maven/in.ksharma/log4j-weblayout/pom.properties

#Generated by Maven 
#Wed Oct 08 19:48:28 IST 2014 
version=0.0.1-SNAPSHOT 
groupId=in.ksharma 
artifactId=log4j-weblayout 

/META-INF/maven/in.ksharma/log4j-weblayout/pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    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>in.ksharma</groupId> 
    <artifactId>log4j-weblayout</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>jar</packaging> 
    <url>https://github.com/Kshitiz-Sharma/log4j-weblayout</url> 
    <properties> 
     <maven.compiler.source>1.6</maven.compiler.source> 
     <maven.compiler.target>1.6</maven.compiler.target> 
    </properties> 
    <dependencies> 
     <!-- Compile dependencies --> 
     <dependency> 
      <groupId>org.apache.velocity</groupId> 
      <artifactId>velocity</artifactId> 
      <version>1.7</version> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.jooq</groupId> 
      <artifactId>joor</artifactId> 
      <version>0.9.3</version> 
      <scope>compile</scope> 
     </dependency> 
     <dependency> 
      <groupId>commons-io</groupId> 
      <artifactId>commons-io</artifactId> 
      <version>2.4</version> 
      <scope>compile</scope> 
     </dependency> 

     <!-- Provided dependencies --> 
     <dependency> 
      <groupId>log4j</groupId> 
      <artifactId>log4j</artifactId> 
      <version>1.2.16</version> 
      <scope>provided</scope> 
     </dependency> 

     <!-- Test dependencies --> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-core</artifactId> 
      <version>4.0.5.RELEASE</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.codehaus.groovy</groupId> 
      <artifactId>groovy-all</artifactId> 
      <version>2.1.8</version> 
      <scope>test</scope> 
     </dependency> 

    </dependencies> 
</project> 
+0

你能請認真發佈罐子裏面的pom內容嗎? – 2014-10-08 14:20:36

+0

@AndrésMongeMoreno請參閱我的編輯。 – 2014-10-08 14:24:57

+0

問題是:你有一個可以用來構建神器的現有pom ...爲什麼不簡單地做:'mvn install'? – khmarbaise 2014-10-08 18:35:27

回答

2

我想你會需要從罐子裏提取的pom.xml和使用其指定pomFile property如下:

mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=log4j-weblayout-0.0.1-SNAPSHOT.jar -DpomFile=pom.xml 
+1

我不認爲這是必要的。該文檔指出:「如果JAR是由Apache Maven構建的,它將在META-INF目錄的子文件夾中包含一個pom.xml,默認情況下它將被讀取。」 – 2014-10-09 03:04:01

+0

我在文檔中看不到安裝文件目標:http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html。有幾個選項聲明可以從包含的pom.xml中提取groupId,artifactId和version,但是我沒有看到您在此處複製的語句。 – 2014-10-09 15:42:20

+1

該句子從問題中提供的[link](http://maven.apache.org/plugins/maven-install-plugin/examples/custom-pom-installation.html)中複製而來。 – 2014-10-18 04:19:39

1

這似乎是一個already fixed bug(2015年1月) ,雖然未修復的最新版本(版本2.5.2根據plugins official site在2014年8月27日發佈)

+0

從理論上講,這個bug已經修復,修復版本在3.0.0中,但在一年後的3.3.3中我仍然看到了同樣的問題。 – 2017-11-06 20:32:01

+0

我在3.5.2中看到了同樣的錯誤。 – 2018-02-19 16:43:15

相關問題