简体   繁体   English

org.apache.velocity.exception.ResourceNotFoundException:无法找到资源“模板/电子邮件/test.vm”

[英]org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'templates/email/test.vm'

My code as follow. 我的代码如下。

VelocityEngine ve = new VelocityEngine();
        ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "class");
        ve.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        ve.init();
        Template tempalte = ve.getTemplate("templates/email/test.vm");

I am getting following error. 我收到以下错误。

org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'templates/email/test.vm' at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:452) at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:335) at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1102)..... org.apache.velocity.exception.ResourceNotFoundException:无法在org.apache.velocity的org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:452)上找到资源'templates / email / test.vm' .runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:335)在org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1102).....

"template" folder is in my src folder. “模板”文件夹在我的src文件夹中。

If I directly put the velocity template file into src folder and update as "Template tempalte = ve.getTemplate("test.vm");" 如果我将速度模板文件直接放入src文件夹并更新为“ Template tempalte = ve.getTemplate(“ test.vm”);“ it works. 有用。

I am using Mac OS, Java 1.8, Eclipse Neon. 我正在使用Mac OS,Java 1.8,Eclipse Neon。

Please help me to solve this. 请帮我解决这个问题。

Thanks and Regards, IsuruJ 感谢和问候,IsuruJ

Try to set below variables and check it should work 尝试设置以下变量并检查它是否可以正常工作

ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "class,file");
        ve.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.Log4JLogChute");
        ve.setProperty("runtime.log.logsystem.log4j.logger", "VELLOGGER");
        ve.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
        ve.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogSystem");

And your velocity file should be under resources folder 而且您的力度文件应位于resources文件夹下

The above way i have it my project if that not working try this 上面的方式我有我的项目,如果那不能正常尝试

I believe your folder structure like /src/main/java/com/xyz/email/velocity/. 我相信您的文件夹结构如/src/main/java/com/xyz/email/velocity/.

ve.velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER,"classpath");
  ve.velocityEngine.setProperty("classpath.resource.loader.class",ClasspathResourceLoader.class.getName())

Few Issues may cause it 几个问题可能会导致它

  1. Templates folder is the root of velocity so removing it may work 模板文件夹是速度的根源,因此删除它可能会起作用

    ve.getTemplate("/email/test.vm"); ve.getTemplate(“ / email / test.vm”);

  2. File with uppercase which is ignored by windows as: folder Email or file Test.vm cannot be found Windows将忽略的大写文件为:找不到文件夹电子邮件或文件Test.vm

  3. Permissions of new folder/file not allowing read if user not owner 如果用户不是所有者,则不允许读取新文件夹/文件的权限

Thanks for your time. 谢谢你的时间。 This is an ANT project. 这是一个ANT项目。 Mistakenly I couldn't write script to copy templates folder to WEB-INF/classes folder. 我错误地无法编写脚本将模板文件夹复制到WEB-INF / classes文件夹。 That was the issue. 那就是问题所在。 Both @user7294900 and @soorapadman are correct. @ user7294900和@soorapadman都是正确的。 The code works now. 该代码现在可以使用。

Really sorry for the inconvenience. 不便之处,敬请原谅。

Best Regards, IsuruJ 最好的问候,IsuruJ

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Velocity模板-线程“ main”中的异常org.apache.velocity.exception.ResourceNotFoundException:无法找到资源 - Velocity Template - Exception in thread “main” org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource org.apache.velocity.exception.ResourceNotFoundException - org.apache.velocity.exception.ResourceNotFoundException Apache velocity:org.apache.velocity.exception.ResourceNotFoundException - Apache velocity: org.apache.velocity.exception.ResourceNotFoundException 如何在模式生成期间修复“org.apache.velocity.exception.ResourceNotFoundException” - How to fix “org.apache.velocity.exception.ResourceNotFoundException” during schema generating 错误[org.apache.velocity] ResourceManager:无法在任何资源加载器中找到资源“ layout.vm” - ERROR [org.apache.velocity] ResourceManager : unable to find resource 'layout.vm' in any resource loader 错误org.apache.velocity:ResourceManager:无法在任何资源加载器中找到资源'xxx.html.vm' - ERROR org.apache.velocity : ResourceManager : unable to find resource 'xxx.html.vm' in any resource loader Apache Android 中的速度(“无法找到资源”) - Apache Velocity in Android("unable to find resource") 将另一个vm文件包含到速度模板中时找不到资源 - Unable to find resource while include another vm file into velocity template 在任何资源加载器中获取速度错误“无法找到资源'error.vm'。” - Getting velocity error “unable to find resource 'error.vm' in any resource loader.” 速度引擎无法找到资源 - Velocity engine unable to find resource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM