Monday, November 21, 2011

WEB-INF and CLASSPATH

Back again to Classpath.

When the web server runs your web application, it looks at the WEB-INF/classes and WEB-INF/lib to find classes. If you put your class or jar somewhere else, it will not find it.

One result of this is that you will often find *.properties files in WEB-INF/classes.

Just like .class files, Java classloaders also look for .properties files in the Classpath. So if your application needs a .properties file, it needs to be in the Classpath - which for a web application is the WEB-INF/classes or WEB-INF/lib

Maybe there should have been a WEB-INF/properties - but somebody didn't think of that, so we have to do this workaround of putting the properties files in /classes.

No comments: