如何在Maven中部署父项目打包战争 [英] How to deploy parent project packaging war in maven

查看:178
本文介绍了如何在Maven中部署父项目打包战争的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以建议我一个解决方案,但以下情况除外.我将创建一个多模块项目.

Could anybody suggest me an solution with the following exception. I am going to create a multi-module project.

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

Parent project name is projectW and child project names are projectA, projectD and projectUtil.

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

I need to have war file of projectW which should contain projectA, projectD and projectUtil. jar file.

但是maven必须在父项目中pom进行打包.如何创建这样的项目?

But maven must pom for packaging in parent project. How can I create a project like this?

推荐答案

拥有父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看起来像这样

Then projectW pom looks something like this

<?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看起来像这样

Then your projectA, projectD and projectUtil will looks something like this

<?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

When you build the parent, the war you want will be projectW/target/projectW-1.0-SNAPSHOT.war

这篇关于如何在Maven中部署父项目打包战争的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆