2015-11-09 37 views
0

我有一個Pom.xml我想知道是否有一種方法讓Pom從某處下載父POM,然後引用父POM。有一個Pom.xml下載並引用一個父Pom

編輯:我在與父POM的問題,這是父POM我

<?xml version="1.0" encoding="UTF-8"?> 
<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>dev</groupId> 
    <artifactId>company-parent</artifactId> 
    <version>1.0.0-SNAPSHOT</version> 
    <packaging>pom</packaging> 

<distributionManagement> 
    <repository> 
     <id>Artifactory</id> 
     <name>Artifactory-releases</name> 
     <url>http://artifactory:8081/artifactory/dev</url> 
    </repository> 
    <snapshotRepository> 
     <id>Artifactory</id> 
     <name>Artifactory-snapshots</name> 
     <url>http://artifactory:8081/artifactory/dev</url> 
    </snapshotRepository> 
</distributionManagement> 

</project> 

我已經上傳了父母的pom.xml到artifactory的,這裏是我的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>maven.Test</groupId> 
    <artifactId>Hello</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>Artifactory</name> 
    <url>http://artifactory:8081/artifactory/webapp/home.html?0</url> 

    <dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.8.2</version> 
     <scope>test</scope> 
    </dependency> 
    </dependencies> 

<parent> 
    <groupId>dev</groupId> 
    <artifactId>company-parent</artifactId> 
    <version>1.0.0</version> 
</parent> 

</project> 

但是當我運行它,我得到這個錯誤

[ERROR]  Non-resolvable parent POM for maven.Test:Hello:1.0-SNAPSHOT: Could n 
ot find artifact dev:company-parent:pom:1.0.0 in central (https://repo.maven.a 
pache.org/maven2) and 'parent.relativePath' points at wrong local POM @ line 22, 
column 9 -> [Help 2] 

如何我有我的雙響炮找到自己artifactory的實例中的神器?

+0

這是有點不清楚你的意思。父POM會自動下載並安裝在本地存儲庫中。 – Daniel

+0

啊好吧,讓我試着更好地解釋這一點,我想讓Parent Pom託管在某處,就像在Artifactory上一樣。然後我想讓我的電腦上的Pom.xml運行一個命令來下載父Pom並引用它。這有幫助嗎? – Macauley

+0

可能的重複[從遠程存儲庫下載父pom](http://stackoverflow.com/questions/12566835/download-parent-pom-from-remote-repository) –

回答

1

你的父母pom應該是pompackaging類型的pom。 e.g:

<?xml version="1.0" encoding="UTF-8"?> 
< 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>org.example</groupId> 
    <artifactId>parent</artifactId> 
    <version>1.0</version> 
    <packaging>pom</packaging> 

</project> 

pom,上面提到的,你可以部署到artifactory的之後,你可以在孩子pom引用它的父POM。例如:

<?xml version="1.0" encoding="UTF-8"?> 
<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"> 
    <parent> 
     <artifactId>parent</artifactId> 
     <groupId>org.example</groupId> 
     <version>1.0</version> 
    </parent> 
    <modelVersion>4.0.0</modelVersion> 

    <artifactId>child</artifactId> 

    <repositories> 
     <repository> 
      <id>Artifactory-Releases</id> 
      <url>http://artifactory:8081/artifactory/dev</url> 
      <snapshots> 
       <enabled>false</enabled> 
      </snapshots> 
      <releases> 
       <enabled>true</enabled> 
      </releases> 
     </repository> 
     <repository> 
      <id>Artifactory-Snapshots</id> 
      <url>http://artifactory:8081/artifactory/dev</url> 
      <snapshots> 
       <enabled>true</enabled> 
      </snapshots> 
      <releases> 
       <enabled>false</enabled> 
      </releases> 
     </repository> 
    </repositories> 
</project> 
+0

@EngineerDollery,謝謝。它來自IDE當我創建了一個測試項目:) –

+0

即使父pom被託管在其他地方,這工作嗎?我不需要有一個鏈接或什麼東西到父母的地方嗎?我目前有我的Pom使用相對路徑引用父代。 – Macauley

+0

如果將pom部署到任何maven存儲庫,它將工作。這個存儲庫將在pom中配置。 –

相關問題