2015-08-26 41 views
0

我的項目包括三個子項目,和我的父POM的樣子:如何依靠這個Maven項目

<groupId>com.bwort.core</groupId> 
<artifactId>bwort</artifactId> 
<packaging>pom</packaging> 
<version>0.0.1-SNAPSHOT</version> 

<name>bwort</name> 

<modules> 
    <module>proj1</module> 
    <module>proj2</module> 
    <module>proj3</module>    
</modules> 

現在我的項目需要依賴於以下項目,其中包括三個子項目,與父母pom。特別是,它已經擁有如下父: https://github.com/cmusphinx/sphinx4/blob/master/pom.xml

<parent> 
    <groupId>org.sonatype.oss</groupId> 
    <artifactId>oss-parent</artifactId> 
    <version>7</version> 
    </parent> 

    <groupId>edu.cmu.sphinx</groupId> 
    <artifactId>sphinx4-parent</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>pom</packaging> 

我的問題是,我該如何申報我的父POM文件的依賴?我可以添加其他模塊到我的父POM:

<module>sphinx4</module> 

但由於該庫中已經定義了自己的父母「OSS父」,那我怎麼才能讓我的父POM作爲其父?

我的項目依賴於此項目的正確方法是什麼?謝謝。

EDITTED:我的pom.xml

<project > 
    <modelVersion>4.0.0</modelVersion> 

    <parent> 
    <groupId>com.bwort.core</groupId> 
    <artifactId>bwort</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    </parent> 

    <artifactId>wikipedia</artifactId> 
    <packaging>jar</packaging> 


    <repositories> 
     <repository> 
      <id>snapshots-repo</id> 
      <url>https://oss.sonatype.org/content/repositories/snapshots</url> 
      <releases><enabled>false</enabled></releases> 
      <snapshots><enabled>true</enabled></snapshots> 
     </repository> 
    </repositories> 

    <dependencies> 

    <dependency> 
     <groupId>edu.cmu.sphinx</groupId> 
     <artifactId>sphinx4-core</artifactId> 
     <version>1.0-SNAPSHOT</version> 
    </dependency> 
    <dependency> 
     <groupId>edu.cmu.sphinx</groupId> 
     <artifactId>sphinx4-data</artifactId> 
     <version>1.0-SNAPSHOT</version> 
    </dependency> 

</dependencies> 

</project> 
+0

請告訴我,如果這能幫助你 - > HTTP:// stackoverflow.com/questions/13487075/is-cmu-sphinx-available-via-maven –

+0

這絕對有幫助。但是在版本庫URL和依賴項之後,我收到了這個「Missing artifact edu.cmu.sphinx:sphinx4-data:jar:1.0-SNAPSHOT」。我正在使用我自己的連接庫。 – user697911

+0

請檢查這個罐子是否存在於你的連接點上。如果不存在,請按照Iker Aguayo給出的上述鏈接中的說明在pom.xml中指定它的存儲庫。 – asg

回答

1

如果你的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/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.mycompany.app</groupId> 
    <artifactId>my-app</artifactId> 
    <packaging>jar</packaging> 
    <version>1.0-SNAPSHOT</version> 
    <name>my-app</name> 
    <url>http://maven.apache.org</url> 
    <repositories> 
     <repository> 
      <id>snapshots-repo</id> 
      <url>https://oss.sonatype.org/content/repositories/snapshots</url> 
      <releases> 
       <enabled>false</enabled> 
      </releases> 
      <snapshots> 
       <enabled>true</enabled> 
      </snapshots> 
     </repository> 
    </repositories> 
    <dependencies> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>3.8.1</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>edu.cmu.sphinx</groupId> 
      <artifactId>sphinx4-core</artifactId> 
      <version>1.0-SNAPSHOT</version> 
     </dependency> 
     <dependency> 
      <groupId>edu.cmu.sphinx</groupId> 
      <artifactId>sphinx4-data</artifactId> 
      <version>1.0-SNAPSHOT</version> 
     </dependency> 
    </dependencies> 
</project> 
+0

是的,我編輯過,類似於你的。 POM不報告錯誤,但是當我檢查〜/ .m2/repository/org/sonatype/oss/oss-parent/7 /時,它只顯示oss-parent-7.pom文件,沒有jar。沒有罐子。爲什麼不報告錯誤? – user697911

+0

你有沒有,mvn包?因爲我做了,並且依賴關係被下載了 –

+0

我可以看到它們是從屏幕上的消息下載的「下載:https://oss.sonatype.org/content/repositories/snapshots/edu/cmu/sphinx/sphinx4-core /1.0-SNAPSHOT/sphinx4-core-1.0-20150630.174404-9.jar(1184 KB在614.7 KB /秒) 下載:https://oss.sonatype.org/content/repositories/snapshots/edu/cmu/sphinx/ sphinx4-data/1.0-SNAPSHOT/sphinx4-data-1.0-20150630.174256-9.jar(36900 KB at 3456.9 KB/sec)「,但我在〜/ .m2/repository/org/sonatype/oss中看不到它/ oss-parent/7 /,只有三個文件「oss-parent-7.pom oss-parent-7.pom.sha1 _remote.repositories」。沒有看到錯誤。 – user697911

2

不,你不增加模塊,您的POM引用其他民族的模塊。

當執行mvn install和or或mvn deploy時,它會將pom.xml文件中定義的工件複製到本地或遠程存儲庫中。所以希望你想依賴的項目可以在Maven中心獲得。

我的建議是添加一個依賴管理部分打包放在父母的pom.xml:

<properties> 
    <sphinx.version>1.0-SNAPSHOT</sphinx> 
</properties> 
<dependencyManagement> 
    <dependencies> 
    <dependency> 
     <groupId>edu.cmu.sphinx</groupId> 
     <artifactId>sphinx4-module1</artifactId> 
     <version>${sphinx.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>edu.cmu.sphinx</groupId> 
     <artifactId>sphinx4-module2</artifactId> 
     <version>${sphinx.version}</version> 
    </dependency> 
    </dependencies> 
</dependencyManagement> 
在自己的模塊之一的pom.xml

添加依賴關係,你需要到依賴關係部分: 請注意版本現在在父級中定義。

<dependencies> 
    <dependency> 
     <groupId>edu.cmu.sphinx</groupId> 
     <artifactId>sphinx4-module2</artifactId> 
    </dependency> 
    </dependencies> 

我會建議不要使用其他人的應用-SNAPSHOT版本 - 它往往會造成因創建快照時,當行家檢索它建立失敗。

如果獅身人面像並不是一個倉庫,你首先需要做mvn install本地

而且我會建議行家教程:

他們解釋了很多,以及:)

相關問題