Hello,

I just started with Maven also, but it appears that when you are running your test case the classpath will be set to both testproject/target/classes and testproject/target/testclasses. Are these resources you need for a test or something and you won't know how many are there? ie: you need to run all of them?

Tell us more about what you are trying to accomplish. I think I would maybe have a directory off test and put them in there and access them not as a resource but as a file. Then you can get a directory listing and be done with it. Otherwise you need to specify the name of the resources to fetch somewhere..

thanks,

-jr


zagu2 wrote:
I'm using Eclipse and m2eclipse. Say I have a project like this:

testproject
- src
-- main
--- java
---- MainClass.java
--- resources
---- 1.txt
---- 2.txt
-- test
--- java
---- TestClass.java
--- resources
---- 3.txt

Now, I can have some code in TestClass doing something like:

this.getClass().getResource("/n.txt")

where n = 1, 2, 3 and it will fetch the appropriate file correctly - I can
get to each of the above text files, which is expected.
However, I don't seem to find a way to fetch any text resource (i.e. *.txt),
tried the following:
- Use getResource and alikes - cannot do *.txt since the resource must be
fully named (asterisks don't work)
- Use getResource to find where compiled TestClass.class is stored and find
*.txt from that folder, since Maven separates these into target/classes and
target/test-classes, so I can only find 3.txt
- Get directly to source (i.e. src/main/resources and src/test/resources,
since I know their location), since I don't know how get to the project's
root (i.e. get path to the testproject)

I know I can do the absolute /a/b/.../z/workspace/testproject/..., but
that's very unportable. Another way would be to make a file with a known
name which would list all the resources, but that's lame (non-DRY), too. Did
you have problems like this and, if so, how did you solve them?

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to