Where to place properties files when running tests via maven + grizzly + jersey test framework?

StackOverflow https://stackoverflow.com/questions/16951963

  •  31-05-2022
  •  | 
  •  

Question

The my.properties file from my source (src/main/resources) folder keepa getting picked up and used when I try to run my JerseyTest ... whereas I would like the properties files in the test folder (src/test/resources) to be utilized.

ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
    myProperties.load(classLoader.getResourceAsStream("my.properties"));
}

How can I configure this in Maven?

I'm using:

  1. maven-compiler-plugin version 2.1
  2. jersey-test-framework-grizzly2 version 1.13

UPDATE (Resolved based on accepted answer):

I noticed the text skip non existing resourceDirectory:

[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) @ xxx ---
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /xxx/xxx/xxx/xxx/src/test/resources

Turns out that I had misspelled resources, after fixing it, everything works as outlined in the accepted answer.

While I was wasting my time looking for workarounds, I did find some interesting links for configuring properties files based on profiles:

  1. How can I change a .properties file in maven depending on my profile?
  2. http://maven.apache.org/guides/mini/guide-building-for-different-environments.html
Was it helpful?

Solution

When running something from the src/test/java folder, the default behavior is:

  • It will pick up the files in src/main/resources;
  • Except when there is a file with the same name in src/test/resources.

So basically it will "overwrite" the content of src/main/resources with the content of src/test/resources:

  • If you got a file in both folders, the one in src/test/resources will prevail.
  • If you got a file only in src/main/resources, it will be used.
  • If you got a file only in src/test/resources, it will be used.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top