ResourceNotFoundException on existing path

293 Views Asked by At

I have the following class:

public class EmailService {

    static {
        Velocity.setProperty("resource.loader", "class");
        Velocity.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        Velocity.init();
   }
   public void sendTerminalModerationStatusChangedEmail(Terminal terminal, String to) {
        ...
        Template subjectTemplate = null;
        try {
            subjectTemplate = Velocity.getTemplate(existedPath, "UTF-8");
        } catch (URISyntaxException e) {
            e.printStackTrace();  
        }
        ...
   }
}

In debug I see that existed path really exists. but I got following error:

Unable to find resource 'C:/Program Files (x86)/apache/apache-tomcat-7.0.52/webapps/ROOT/WEB-INF/classes/velocityTemplates/terminalModerationStatusChanged.vm'

But file C:/Program Files (x86)/apache/apache-tomcat-7.0.52/webapps/ROOT/WEB-INF/classes/velocityTemplates/terminalModerationStatusChanged.vm really exists on my mashine and I can navigate to it if type copied path to address line.

1

There are 1 best solutions below

0
On BEST ANSWER

Instead of using the full absolute path, load it from classpath, because it is already in classes folder.

subjectTemplate = 
     Velocity.getTemplate("velocityTemplates/terminalModerationStatusChanged.vm", "UTF-8");