I am unable to locate the file while using ${user.dir} to avoid hardcoding in the @Config.Sources annotation of the Owner library in Java to locate the property file.

Using the absolute path to locate the file works for me perfectly as shown below

@Config.Sources(value="C:\\Users\\username\\eclipse-workspace\\MWAFW\\src\\test\\resources\\FrameworkConfig.properties")
public interface FrameworkConfig extends Config {
    ...
}

However, If I use

@Config.Sources(value="${user.dir}\\src\\test\\resources\\FrameworkConfig.properties")
public interface FrameworkConfig extends Config {
    ...
}

or

@Config.Sources(value="${user.dir}/src/test/resources/FrameworkConfig.properties")
public interface FrameworkConfig extends Config {
    ...
}

does not locate the properties file. Why is ${user.dir} not working for me in this case?

  • I am using a maven-Java project on Intellij community edition
1

There are 1 best solutions below

0
Abhay Chaudhary On

You can try below steps to solve it

  1. Print the value of ${user.dir} to the console or log file to verify that it resolves to the expected directory

  2. using an absolute path to the property file

     @Config.Sources(value="/src/test/resources/FrameworkConfig.properties")
         public interface FrameworkConfig extends Config {
         }
    
  3. In IntelliJ IDEA, you can set the working directory in the Run/Debug Configuration for your application try checking, make sure that the working directory is set correctly

  4. Using classpath

     @Config.Sources(value="classpath:FrameworkConfig.properties")
     public interface FrameworkConfig extends Config {
        ...
     }