父POM中声明的项目名称不会在模块过滤的web.xml中扩展 [英] Project name declared in parent POM isn't expanded in a module filtered web.xml

查看:92
本文介绍了父POM中声明的项目名称不会在模块过滤的web.xml中扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Maven多模块项目(您可以在此处了解其他详细信息)中,我已启用web.xml过滤webapp模块,以便我可以在其中引用Maven属性.

In my Maven multi-module project (you can have a look here for other details), I've enabled web.xml filtering for the webapp module, so that I can reference Maven properties in there.

我定义了:

  1. webapp模块POM中的属性;
  2. 父POM中的属性;
  3. 父POM中的Maven <name />元素.
  1. a property in the webapp module POM;
  2. a property in the parent POM;
  3. the Maven <name /> element in the parent POM.

在打包的web.xml文件中,[1]和[2]中的属性都可以正确扩展,但是父<name />标记不是—.如果我在webapp-module中声明该元素,则会对其进行正确扩展.

The properties in [1] and [2] are both expanded correctly in the packaged web.xml file, but the parent <name /> tag is not — if I declare that element in the webapp-module it is correclty expanded.

我错过了什么吗?这是预期的行为吗?

Am I missing something? Is this the expected behaviour?

以下是所涉及的各种XML文件的相关部分.

Here are the relevant parts of the various XML files involved.

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">

    <display-name>shaker-multi-webapp webapp-value parent-value 1.0</display-name>
</web-app>

web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">

    <display-name>${project.name} ${webapp.prop} ${par.prop} 1.0</display-name>
</web-app>

Webapp POM

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

    <parent>
        <groupId>sunshine.web</groupId>
        <artifactId>shaker-multi</artifactId>
        <version>0.0.1</version>
    </parent>

    <artifactId>shaker-multi-webapp</artifactId>
    <packaging>war</packaging>

父母POM

<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>sunshine.web</groupId>
    <artifactId>shaker-multi</artifactId>
    <version>0.0.1</version>
    <packaging>pom</packaging>

    <name>Shaker</name>

    <modules>
        <module>shaker-multi-core</module>
        <module>shaker-multi-runnable</module>
        <module>shaker-multi-webapp</module>
        <module>shaker-multi-webapp-muserver</module>
    </modules>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <par.prop>parent-value</par.prop>
    </properties>

推荐答案

要获取在父POM中声明的名称,应使用${parent.name}而不是${project.name},因为不会继承项目名称(查找更多详细信息)在 Maven来源中).

To get the name declared in the parent POM, ${parent.name} should be used instead of ${project.name}, since project names aren't inherited (find more details in Maven sources).

信贷从#maven@irc.codehaus.org转到 rfscholte .

这篇关于父POM中声明的项目名称不会在模块过滤的web.xml中扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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