在Maven Pom文件中读取环境变量

时间:2019-04-23 16:04:31

标签: java linux windows maven

我试图将环境变量读取到maven pom文件中,并基于此需要在war软件包中包含特定的web.xml文件。所以我做了以下配置。

          <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>

                    <includeEmptyDirectories>true</includeEmptyDirectories>
                    <warSourceExcludes>**/web_*.xml,**/spring/securityContext_*.xml</warSourceExcludes>
                    <webResources>
                        <resource>
                            <directory>src/main/webapp/WEB-INF</directory>
                            <targetPath>WEB-INF</targetPath>
                            <filtering>true</filtering>
                            <includes>
                                <include>**/securityContext_${env.TESTENV}.xml</include>
                            </includes>
                        </resource>
                    </webResources>
                    <webXml>${dir.web}/web_${env.TESTENV}.xml</webXml>
                </configuration>
            </plugin>

但是env.TESTENV测试没有启动。出现以下错误。

The specified web.xml file 'xxxxxxx\xxx\xxxx\src\main\webapp\WEB-INF\web_${env.TESTENV}.xml' does not exist -> [Help 1]

仅出于测试目的,我将“ TESTENV”替换为“ PATH”,这是对以web.xml附加的路径的命名。

所以我的问题是如何使其工作?

我之前用-Dxxx在路径中提供了变量,但是由于某些原因,我应该只从系统属性中选择该变量。

仅供参考:我正在使用Windows,并在系统属性和用户属性中定义了TESTENV。

0 个答案:

没有答案