It's not a secret anymore!
The moose likes Ant, Maven and Other Build Tools and the fly likes Resource Filtering issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Resource Filtering issue" Watch "Resource Filtering issue" New topic

Resource Filtering issue

Jaaouane Aymen

Joined: Sep 22, 2009
Posts: 29
Hello all,

I have a properties file wich will contain the adresses of the servers that i will send requests to . The properties file will have the good values only when packaging because maven will fill them thanks to its profiles.
So my file looks like this:

So far all is good, but the problem is that i am writing a unit test which must read the ip from the properties file. the test fails because it can not connect to the server because the ${travelfusion.ip} will be returned and not a good value. i am launching the unit test from Eclipse so maven is not in the process and the variables are not replaced by good values.

Must i launch unit tests only by maven? or there is a way to keep the variables in the properties file and writing unit tests which can read good values from the properties file?

Thank you in advance,
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33117

I feel like there should be a more direct way to do what you want, but one alternative is to read a different physical "dev" file for unit testing. Or have a test more. Or pass the properties into your code.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Peter Johnson

Joined: May 14, 2008
Posts: 5852

I would run the test via Maven. In Eclipse you can do Run As | Maven Package, that will both compile the code and run the unit tests, and the filter will have happened.

And I really like the fact that with Maven you don't have to have two sets of properties files, that profiles will handle the differences between production, test and development.

JBoss In Action
I agree. Here's the link:
subject: Resource Filtering issue
It's not a secret anymore!