I created java enterprise application and it consists of ejb module and web application. I have plain old xml file in source packages folder in package “common” in my ejb module. I want to pass this file path in File() constructor for one class in ejb module. How do i do it?
If i pass any of the below it doesn’t work :-
new File("abc.xml"); //this take file from glassfish/domains/domain1 :(
new File("./abc.xml");
I don’t want to pass hardcode path like /home/administrator/appname/module/etc..
I want the path relative from my ejb module. Please help me. I’ve tried all things.
Actually when i created a class in same folder and then try classname.getResource("abc.xml").getPath() it works fine. But what if i don’t have any class in that folder. Waiting for your replies
Like you’ve already guessed, you should use
this.getClass().getResource("/common/abc.xml").getFile()— it will work for any class of your application since it uses class loader to locate a resource in class path. See javadocs if you run into trouble.