文件中的Maven过滤参数

时间:2018-07-23 19:39:50

标签: java maven

我一直在寻找Maven War插件及其配置方法。这是我的情况。我有一个Web应用程序,已分发到多个生产设施。在此Web应用程序中,有两个文件是针对每种设施定制的。这些是/js/config.js和/META-INF/context.xml。

我的项目具有典型的Maven结构:

/src
|--/main
   |--webapp
      |--/js
         |--config.js
         |--properties
            |--plant.properties
      |--/META-INF
         |--context.xml

为了简洁起见,我省略了不必要的目录。

config.js已更改为包含我要替换的“参数”:

var Config {
    ...
    system_title: '${plant_name} - Audit System',
    ...
}

我pom的相关部分是:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.0</version>
        <configuration>
            <filters>
                src/main/webapp/js/properties/fayetteville.properties
            </filters>
            <failOnMissingWebXml>false</failOnMissingWebXml>
            <webResources>
                <resource>
                    <directory>src/main/webapp/js</directory>
                    <filtering>true</filtering>
                    <exclude>**/properties</exclude>
                </resource>
            </webResources>
        </configuration>
    </plugin>

当我运行“ mvn clean package”时,我希望看到$ {plant_name}被替换为属性文件中的内容。在这种情况下,我的属性文件包含一个键值对:

plant_name=Austin

但是我没有看到替代品。在目标文件夹中生成的config.js仍然包含$ {plant_name},与在生成的war文件中的config.js一样。

如果可能的话,我真的不想使用个人资料。最终,我希望构建过程使用属性文件列表来对所有工厂执行此操作。

根据我的研究,包括一些SO问题和答案,我觉得自己的配置正确。

我可能做错了什么?

0 个答案:

没有答案