我正在在运行时从pom.xml
更改属性文件的值。我看到目标文件夹中的属性文件的值发生了更改,但是当我访问显示实际值的Java代码中的属性值时
application.properties
gapp=${testName}
java代码
java.io.InputStream is = this.getClass().getResourceAsStream("/application.properties");
java.util.Properties p = new Properties();
p.load(is);
String name = p.getProperty("gapp");
System.out.println("prop "+name);
pom.xml
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<testName>pravin</testName>
</properties>
<build>
<resources>
<resource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/phomeTestNg.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
目标文件夹:
答案 0 :(得分:0)
在重新部署应用程序之前,尝试的方法将不起作用。但是,许多平台有多种使用方式,例如https://tompeez.wordpress.com/2015/01/13/change-application-configuration-at-run-time-through-a-properties-file-part-1/