I am trying a simple web application in tomcat 7. It has a javascript call in the index.html which loads a properties file. Using the below code to make a get call,
var req = new XMLHttpRequest();
req.open("GET", "xyz.properties");
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {
}
}
}
req.send();
Tried the following usecases,
- Kept the properties file directly inside the war file, i.e. outside WEB-INF - This works.
- Kept it under WEB-INF/classes - Did not work.
- Wrapped it in a jar and kept it under WEB-INF/lib - Did not work.
- Put the jar under Tomcat/lib - Did not work.
As far as i understand, every resource/class request goes through the WebAppClassloader, which look at things in the following order,
- Jvm Boot Strap
- system loader
- web-inf/classes
- web-inf/lib
- shared/lib
In my actual application i am using an embedded tomcat and the goal is to externalize(out side of the war) the property file via a jar. Hence the above tests to understand the basic resource loading for tomcat.
Can someone throw some light around what's missing with the above tests. Typically if the get request goes through the class loader, shouldn't it be able to find the file in all cases.