Velocity Example终于跑起来了。

遇到的问题:

一、运行官方例子中的./example.sh出错。出现以下错误

shaoyongyang@Hack:~/Desktop/velocity/velocity-1.7/examples/app_example1$ ./example.sh
Running Example with input file 'example.vm'
错误: 找不到或无法加载主类 Example

      尝试解决./example.sh脚本问题:

     

for i in ../../bin/*.jar
do
    _VELCP=$_VELCP:"$i"
done

for i in ../../build/lib/*.jar
do
    _VELCP=$_VELCP:"$i"
done

通过上面代码可以看出环境变量需要jar包。或者目录等。   然后去那个目录寻找。

shaoyongyang@Hack:~/Desktop/velocity/velocity-1.7/build$ ls
build.properties  download.xml          lib            xsl
build.xml         findbugs-exclude.xml  testcases.xml
shaoyongyang@Hack:~/Desktop/velocity/velocity-1.7/build$ 

可以看到需要ant下载。结果运行ant。下载出错,连接不到服务器。



百思不得其解的时候。看到大侠用maven解决了jar包依赖的问题。

1、新建maven工程

2、拷贝Example.java到工程目录

3、加入pom.xml依赖

<dependency>
  <groupId>org.apache.velocity</groupId>
  <artifactId>velocity</artifactId>
  <version>1.7</version>
</dependency>
4、加入example.vm和velocity.proerties到src目录

5、寻找到main方法  修改为 Example t = new Example("/src/example.vm");  



最后运行!!! 出现了!



Velocity is great!

    ArrayList element 1 is great!
    ArrayList element 2 is great!
    ArrayList element 3 is great!
    ArrayList element 4 is great!


    The condition is true!


最后:虽然不知道为什么解决了,但是总算解决了。

附图一张:

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值