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?



    <!-- Add profiles for other environments as needed -->



public class ConfigurationReader {
    private static Properties properties = new Properties();
    static {
        String env = System.getProperty("env","qa");
        try {
            FileInputStream file = new FileInputStream(env+".properties");

        } catch (IOException e) {
            System.out.println("Properties file not found.");

    public static String getProperty(String keyWord){
        return properties.getProperty(keyWord);


1 Answer 1


You still need to pass the argument: You mvn install command doesn't do this.

But you don't need surefire for this.

You can simply run:

mvn install -Denv='qa'


mvn install -Denv='uat'

Then System.getProperty("env") will return the equivalent string you passed.

  • Hello Joao, Can I set the env value in the pom.xml file and run the Cucumber Runner class to execute the tests based specific to the env value? Dec 19, 2023 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.