Friday, September 17, 2010

Load the xml file from the class which is in the same Jar file

Lets assume you have a class called samle and xml file called sample.xml file. Both class and xml files are in the jar file.

If you want to load the sample.xml from the sample.class file, you need to use the following code.

this.getClass().getClassLoader().getResource("sample.xml")

Sample examples:

public class Sample {
public void callXmlMapping() {
URL url = this.getClass().getClassLoader().getResource("sample.xml");
}
}


You can create jar file with these both files and add this jar file in class path of your webapplication.

No comments:

Post a Comment