我想从 pom.xml 中获取 artifactId 并使用此 artifactId 填充属性文件。
pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xxxxx</groupId>
<artifactId>fm-service</artifactId>
<packaging>war</packaging>
<version>x.x.x-SNAPSHOT</version>
</project>
application.preperties
email.subject = "ALERT - [artifactId from pom.xml]"
有可能这样做吗?如果是,如何,如果不是,请提出替代方案。
最佳答案
Maven 提供了一种方法 filter resources .
首先,必须将文件 application.properties
放入 src/main/resources
目录中。那么它的内容必须是:
email.subject = "ALERT - ${project.artifactId}"
最后(但并非最不重要)只需将此配置添加到您的 POM 中:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
现在resources目录下的所有文件都会被过滤掉,也就是说里面的所有变量都被解析了。
关于java - 使用 pom.xml 属性填充环境属性文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41607075/