I have some code that works just fine locally, but when I try to run it on my remote server, it throws a null pointer exception. It does so when attempting to get the template from Velocity. It fails the first time, and every time after.
The code in question is this bit:
URL location = Thread.currentThread().getContextClassLoader().getResource("velocity.properties");
String fullPath = location.getPath();
log.debug("Path: " + fullPath);
Velocity.init(fullPath);
Template tmplt = Velocity.getTemplate( "template.html" ); //This line throws the error
Logging shows the path to be correct, and I can verify that the file is there.
The properties file used to initialize velocity contains:
resource.loader = file
file.resource.loader.class = org.apache.velocity.runtime.resource.loader.FileResourceLoader
file.resource.loader.path=/var/lib/tomcat6/webapps/geoip/WEB-INF/templates/template.html
file.resource.loader.cache = true
input.encoding=UTF-8
output.encoding=UTF-8
The stack trace for the error looks like this:
SEVERE: Servlet.service() for servlet Jersey REST Service threw exception
java.lang.NullPointerException
at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1533)
at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1514)
at org.apache.velocity.runtime.RuntimeSingleton.getTemplate(RuntimeSingleton.java:299)
at org.apache.velocity.app.Velocity.getTemplate(Velocity.java:358)
at ca.company.ipservice.models.MyClass.toHTML(MyClass.java:48)
I've Googled around and searched StackOverflow but I can't find any answer. Any ideas?