[英]Velocity Template - Exception in thread “main” org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource
[英]Apache Velocity in Android("unable to find resource")
我使用此代碼到達 temp.vm,但出現此錯誤。 我應該在代碼、文件位置或 Mainfest 中進行哪些更改
PS 這是新項目,所以我有標准清單我試圖將文件保存在資源、資產和主路徑中
2021-05-20 17:11:27.617 17303-17303/com.example.printer E/org.apache.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 );
我不確定將模板文件放在 java 源代碼樹中是否足以讓它們從類路徑中可見。 我們需要查看您的 gradle 腳本。 通常,應該在類路徑中的資源(通常將它們包含在最終的 jar 中)位於resources
目錄中。 在開發模式下,可以嘗試手動將java
目錄添加到classpath中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.