Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 现有路径上的ResourceNotFoundException_Java_Io_Velocity_Resource Loading - Fatal编程技术网

Java 现有路径上的ResourceNotFoundException

Java 现有路径上的ResourceNotFoundException,java,io,velocity,resource-loading,Java,Io,Velocity,Resource Loading,我有以下课程: public class EmailService { static { Velocity.setProperty("resource.loader", "class"); Velocity.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); Ve

我有以下课程:

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();  
        }
        ...
   }
}
在调试中,我看到存在的路径确实存在。但我犯了以下错误:

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

但是文件
C:/Program Files(x86)/apache/apache-tomcat-7.0.52/webapps/ROOT/WEB-INF/classes/velocityTemplates/terminalModerationStatusChanged.vm
确实存在于我的mashine上,如果键入复制到地址行的路径,我可以导航到它。

不要使用完整的绝对路径,而是从类路径加载它,因为它已经在classes文件夹中

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

为什么要使用完整路径,而不是从类路径引用加载它,如
velocityTemplates/terminalModerationStatusChanged.vm
?好的,添加它作为答案。谢谢!