Android中的java Apache Velocity(“无法找到资源”)
我用这个代码来达到温度。vm,但我得到了这个错误。我应该在代码、文件位置或Mainfest中更改什么
另外,这是一个新项目,所以我有标准清单 我已尝试将文件保存在资源、资产和主路径中
2021-05-20 17:11:27.617 17303-17303/com。实例打印机E/org。阿帕奇。velocity:ResourceManager:找不到资源“123/temp”。任何资源加载程序中的“vm”强>
VelocityEngine velocityEngine = new VelocityEngine();
velocityEngine.init();
velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
Template t = velocityEngine.getTemplate("123/temp.vm");
VelocityContext context = new VelocityContext();
context.put("name", "World");
StringWriter writer = new StringWriter();
t.merge( context, writer );
# 1 楼答案
我不确定将模板文件放在java源代码树中是否足以使它们从类路径可见。我们需要看看你的毕业剧本。通常,要在类路径中的资源(通常将它们包括在最终的jar中)位于
resources
目录中。在开发模式下,您可以尝试手动将java
目录添加到类路径