How to access a XML file in a maven project so it stays available when packaged

Posted by Manuel on Stack Overflow See other posts from Stack Overflow or by Manuel
Published on 2010-04-15T06:06:08Z Indexed on 2010/04/15 6:13 UTC
Read the original article Hit count: 229

Filed under:
|

I currently started working on a maven web-app project that needs to be launched with the jetty:run-exploded goal for development/debugging in eclipse.

Now, I have an XML file which contents I need to access at runtime. My problem is: where to put the file so that the code that does the reading works both in "exploded" and packaged (i.e. in the WAR) mode?

Putting the file in src/main/java (so as to be in the classpath) won't cut it since maven filters out all non-java files on packaging. When the file is in src/main/resources, one mean would be to figure out the root path of the project (during eclipse development) and look into that directory - but this won't be the case anymore when the project will be packaged.

Of course I could go into writing code that tries to read the file from both locations, but this seems rather cumbersome. Any suggestions?

© Stack Overflow or respective owner

Related posts about maven

Related posts about java