第一个velocity碰到的问题及解决

文件目录结构:

源程序很简单,就是在网上看到的HelloVelocity如下:
vm为:           Welcome $name to wuweishe.blogchina.com!
java文件为:      import java.io.StringWriter;

import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;


public class HelloVelocity
{
    public static void main(String[] args) throws Exception
    {
        /*  first, get and initialize an engine  */
        VelocityEngine engine = new VelocityEngine();
        engine.init();

        /*  next, get the Template  */
        Template template = engine.getTemplate( "hellovelocity.vm" );

        /*  create a context and add data */
        VelocityContext context = new VelocityContext();
        context.put("name", "World");

        /* now render the template into a StringWriter */
        StringWriter writer = new StringWriter();
        template.merge( context, writer );

        /* display the results */
        System.out.println( writer.toString() );    
    }    
}

编译能通过但运行时提示:
  Exception in thread "main"       java.lang.NoClassDefFoundError:org/apache/commons/collections/ExtendedProperties
at org.apache.velocity.runtime.RuntimeInstance.<init><RuntimeInstance.java:160>
at org.apache.velocity.app.VelocityEngine.<init><VelocityEngine.java:71>
at HelloVelocity.main(HelloVelocity.java:13)
 

可以看出,是org.apache.commons.collections.ExtendedProperties没有加载进去啊,

这个类应该在velocity-dep-1.5.jar下面,所以你肯定没有把velocity-dep-1.5.jar加载到你的类中.

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值