0

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
Community
  • 1
  • 1
pulkitsinghal
  • 3,855
  • 13
  • 45
  • 84

1 Answers1

1

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.
acdcjunior
  • 132,397
  • 37
  • 331
  • 304
  • I understand what you are saying but it picks up the one in `src/main/resources` even when there is a fiel with the same name in `src/test/resources` ... any other suggestions? – pulkitsinghal Jun 06 '13 at 01:57