Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Getting relative reference to file in WAR

843841Nov 24 2004 — edited May 30 2006
Hi

Please could you advise me on how I can get a relative reference to a file in my web application.

Part of my structure is:

I have a class:
<app>/WEB-INF/classes/package/MyClass.class

Which needs to create a file object from:
<app>/WEB-INF/xml/black.xml

As the app could be deployed anywhere and on any OS i need to reference the file relatively in the MyClass class.

Please could someone tell me how to do this. I have tried:

MyClass.class.getResource("xml/black.xml");
getClass().getResource("xml/black.xml");
getClass().getClassLoader().getResource("xml/black.xml")

All return null.

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 27 2006
Added on Nov 24 2004
8 comments
395 views