I have qa.properties
and uat.properties
file in the project. I have added profiles tag, env tag in properties tag and environment in configuration tag of the maven surefire plugin in the pom.xml
file. I have created envProperties.java
class to load the properties based on the env value passed from the pom.xml
or mvn test -Pqa
from command prompt but it is always executing using the deafult value passed in the envProperties.java class.
I have invalidated the caches and loaded the project, executed mvn clean
, mvn install
but still facing the same issue. How can I handle the issue?
pom.xml
:
<properties>
<env>flex</env>
</properties>
<profiles>
<profile>
<id>uat</id>
<properties>
<env>uat</env>
</properties>
</profile>
<profile>
<id>qa</id>
<properties>
<env>qa</env>
</properties>
</profile>
<!-- Add profiles for other environments as needed -->
</profiles>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<includes>
<include>**/*DemoRunner.java</include>
</includes>
<testFailureIgnore>false</testFailureIgnore>
<systemPropertyVariables>
<environment>${env}</environment>
</systemPropertyVariables>
</configuration>
</plugin>
envProperties.java
:
public class ConfigurationReader {
private static Properties properties = new Properties();
static {
String env = System.getProperty("env","qa");
try {
FileInputStream file = new FileInputStream(env+".properties");
properties.load(file);
file.close();
} catch (IOException e) {
System.out.println("Properties file not found.");
}
}
public static String getProperty(String keyWord){
return properties.getProperty(keyWord);
}
}