2017-05-12 72 views
0

有沒有人可以給我一個解決方案,但有以下例外情況。我將創建一個多模塊項目。如何在maven中部署父項目包裝戰

父項目名稱爲projectW,子項目名稱爲projectA,projectDprojectUtil

我需要有戰略檔案projectW其中應包含projectA,projectDprojectUtil。 jar文件。

但maven必須爲包裝父項目。我如何創建這樣的項目?

+0

'projectW'不能是父項目,因爲父項目是包裝類型'pom'。所有項目都是父項目父項目項目'projectP'和'ProjectW'應該具有其他項目作爲依賴關係 – Jens

回答

1

有一個父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"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>com.example</groupId> 
    <artifactId>example</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>pom</packaging> 

    <name>example</name> 

    <modules> 
    <module>projectW</module> 
    <module>projectA</module> 
    <module>projectD</module> 
    <module>projectUtil</module> 
    </modules> 

</project> 

然後projectW POM看起來像這樣

<?xml version="1.0"?> 
<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> 

    <parent> 
    <groupId>com.example</groupId> 
    <artifactId>example</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    </parent> 

    <artifactId>projectW</artifactId> 
    <packaging>war</packaging> 

    <name>projectW</name> 

    <dependencies> 
    <dependency> 
     <groupId>com.example</groupId> 
     <artifactId>projectA</artifactId> 
     <version>${project.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>com.example</groupId> 
     <artifactId>projectD</artifactId> 
     <version>${project.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>com.example</groupId> 
     <artifactId>projectUtil</artifactId> 
     <version>${project.version}</version> 
    </dependency> 
    </dependencies> 

</project> 

然後你了projectA,projectD和projectUtil會看起來像這樣

<?xml version="1.0"?> 
<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> 

    <parent> 
    <groupId>com.example</groupId> 
    <artifactId>example</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    </parent> 

    <artifactId>projectA</artifactId> 
    <packaging>jar</packaging> 

    <dependencies> 
    </dependencies> 

</project> 

當你建立父母,你想要的戰爭將是projectW/target/projectW-1.0-SNAPSHOT.war