我想在我的应用程序中指定一些系统属性(在编译时确定)。
我正在使用Spring Boot Maven插件进行编译
当前,根据以下问题:将系统属性指定为Maven项目,我尝试了以下设置(但是,对于其他插件,它不起作用)
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>application.boot.AppStarter</mainClass>
<systemProperties>
<systemProperty>
<name>application.version</name>
<value>${application.version}</value>
</systemProperty>
<systemProperty>
<name>release.date</name>
<value>${timestamp}</value>
</systemProperty>
</systemProperties>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
如何在此插件中指定属性?
您添加的Java系统属性只能通过添加过程来访问。因此,即使您在Maven构建过程中设法添加了一些系统属性,构建完成后也将不再存在。
如果您将罐子分发给其他人,将会发生什么。您如何期望这些属性可用?
请参阅这篇文章,以了解如何在运行时访问artifactId和版本。您可以通过类似的方式将时间戳记条目添加到src/main/resources/project.properties
buildTimestamp=${timestamp}
timestamp
不是类似project.version
或的预定义属性project.artifactId
。因此,您必须设置从Maven属性提取时间戳${maven.build.timestamp}
,并将其设置为timestamp
属性的值。这个问题已经回答了。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句