如何在maven中部署父项目打包战争

时间:2017-05-12 08:11:59

标签: java eclipse maven

有人建议我使用以下例外的解决方案。我将创建一个多模块项目。

父项目名称为projectW,子项目名称为projectAprojectDprojectUtil

我需要projectW的war文件,其中应包含projectAprojectDprojectUtil。 jar文件。

但是maven必须在父项目中进行包装。我该如何创建这样的项目?

1 个答案:

答案 0 :(得分:2)

有父母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