No, I can't use getResource because the class I'm testing needs to work
on files instead of InputStream or URL. It's reading and writing from/to
a file so it's not possible to switch it over to InputStream/URL. I
should've mentioned that. I could probably parse the URL for the
absolute path of the file but I don't like that either.
I think goals should generally execute the same way if either called by
a parent pom or the module pom itself.
Thanks anyway,
Joern.
Julian Wood wrote:
If I understand your problem correctly, you're having problems
accessing resource files from your unit tests?
I think what you want to do is access your resource files differently.
Note that when the process-test-resources goal is called (as part of
mvn package or install or test, etc), files in src/test/resources are
copied into target/test-classes and as such are available on your
classpath. Thus, in your unit test, you can access the file like so:
Thread.currentThread().getContextClassLoader().getResource("file.txt")
That gives you a URL from which you can get a File, or use one of the
other getResource... methods if you prefer.
This will work no matter what your user.dir is, or from wherever you
execute the tests (ie build your project).
Hope that helps.
J
On 12-Jan-06, at 8:01 AM, Joern Huxhorn wrote:
Hi,
I have the following problem with a multi-module project:
The file structure looks like this
pom.xml (parent pom of modules)
module1/pom.xml
module2/pom.xml
In some of our testcases we need to access files so these files are
located in src/test/resources of the respective project. Everything
works fine as long as I build the project from the submodules path
since the path is specified relative, e.g.
src/test/resources/file.txt. If I try to build all modules using the
parent pom, however, the testcases fail since the file is now
expected in src/test/resources/file.txt realtive to the parent poms
folder.
Is this a bug or a feature? I expected the current dir (user.dir) to
change for every executed sub-module build.
Any ideas how I could solve this problem? Absolute filenames are not
really an option (that's my current workaround and it's a real burden)
Thanks, Joern.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
Julian Wood <[EMAIL PROTECTED]>
Programmer/Analyst
University of Calgary
http://commons.ucalgary.ca
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]