java找不到的模板_java-无法找到速度模板资源

java-无法找到速度模板资源

只是一个基于Maven结构的简单速度独立应用程序。 这是用Scala编写的代码片段,用于呈现${basedir}/src/main/resources文件夹中的模板helloworld.vm:

com.ggd543.velocitydemo

import org.apache.velocity.app.VelocityEngine

import org.apache.velocity.VelocityContext

import java.io.StringWriter

/**

* @author ${user.name}

*/

object App {

def main(args: Array[String]) {

//First , get and initialize an engine

val ve = new VelocityEngine();

ve.init();

//Second, get the template

val resUrl = getClass.getResource("/helloworld.vm")

val t = ve.getTemplate("helloworld.vm"); // not work

// val t = ve.getTemplate("/helloworld.vm"); // not work

// val t = ve.getTemplate(resUrl.toString); // not work yet

//Third, create a context and add data

val context = new VelocityContext();

context.put("name", "Archer")

context.put("site", "http://www.baidu.com")

//Finally , render the template into a StringWriter

val sw = new StringWriter

t.merge(context, sw)

println(sw.toString);

}

}

何时编译和运行程序,出现以下错误:

2012-1-29 14:03:59 org.apache.velocity.runtime.log.JdkLogChute log

严重: ResourceManager : unable to find resource '/helloworld.vm' in any resource loader.

Exception in thread "main" org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource '/helloworld.vm'

at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:474)

at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:352)

at org.apache.velocity.runti

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值