Re: Getting Maven project resources (Eclipse)

2009-09-02 Thread James Russo

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: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org



Re: Getting Maven project resources (Eclipse)

2009-09-02 Thread zagu2

Correct - I want to have an option of getting many files at once. 

In my case, it's the Spring configuration - I have many
applicationContext*.xml files that I just need aggregated, but there are
many other cases - Hibernate mappings, different kinds of property files,
etc. The main motivation is: I want to name all my files prefixSuffix.ext
and load all of them with prefix*.ext. That way if I decide later to, say,
split an applicationContext.xml into 10 pieces (since it became too large),
I don't go and change all the places I load it from. 

Again, in this case it's not that it's that hard - I need to change two
things - the main loader and the test loader classes. However, in general,
there might be many resources and/or resources out of your control. 

To give you an example - say you are building a template engine (like
Velocity) or a wiki engine. Simple - you have an input file, some rules to
translate to output and the output file. Rules are not something the user
needs to specify - they are the internal thing. (Say we don't want the user
to be able to say ok, now I want my Wiki engine to translate h3. into
header level 3 instead of ===). Since they are internal, they seem to be
resources that should be built in directly to the resulting jar, for
example.

Now, I am just starting my wiki engine and I am adding things one by one.
With a file-system approach, I could load, say, some defaults used by these
rules from property files dynamically. I don't want to say: load defaults
for lists, then I add headers and I want to load defaults for headers, then
load defaults for code blocks, then load defaults for paragraphs, then...
Unfortunately, isn't it true that what I need to do now exactly that?

I suppose there are more examples of this. In general, it's - I want to load
many files and not have to specify what in two places - as files themselves
(which already contain a name) and as a list of resources (which just
duplicate the file names).

To summarize - I'm just whining too much about portability here. :) Thanks
James!

-- 
View this message in context: 
http://n2.nabble.com/Getting-Maven-project-resources-Eclipse-tp3568731p3569012.html
Sent from the maven users mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org



Re: Getting Maven project resources (Eclipse)

2009-09-02 Thread James Russo


zagu2 wrote:

I suppose there are more examples of this. In general, it's - I want to load
many files and not have to specify what in two places - as files themselves
(which already contain a name) and as a list of resources (which just
duplicate the file names)
Understand..How about some type of generated class which gets list of 
files in resource directory and generates a class
with a strings[] of the required resource names. This generated class 
would be references from your test to load the right context.


Now, I'm new to maven so I wouldn't have a clue on how to wire that in.. 
I suppose in the code generation phase, maybe

using some type of ant task?

-jr

-
To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org



Re: Getting Maven project resources (Eclipse)

2009-09-02 Thread zagu2

Good thinking, shouldn't bee to hard to be written either. I'd like it more
dynamic, though :) On the other hand, I just had a doh! moment. Seems like
new File(.).getAbsolutePath() gives the execution folder in Eclipse (and
not the classpath root where the class is, like getClass().getResource(/)
does), which solves part of the issue. If you make sure all your
configuration files are in root, you will be able to locate them relatively
from that. *sigh*. It seems this is more a what is a file and what is a
resource type of question for somebody more versed in spring. Should you
embed applicationContext.xml inside the jar? It would allow you to run
jar-only (no external dependencies), but won't enable dynamically changing
the file and future additions without the repacking... :| Just blabing...
Thanks again James!
-- 
View this message in context: 
http://n2.nabble.com/Getting-Maven-project-resources-Eclipse-tp3568731p3569403.html
Sent from the maven users mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org