好吧,它在Eclipse中工作。只需将所有Velocity Jar文件添加到我的Dynamic Web Project中WEB-INF文件夹的lib目录即可。然后更新web.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Velocity_Test</display-name>
<welcome-file-list>
<welcome-file>index.vm</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- Define Velocity template compiler -->
<servlet>
<servlet-name>velocity</servlet-name>
<servlet-class>org.apache.velocity.tools.view.servlet.VelocityViewServlet</servlet-class>
</servlet>
<!-- Map *.vm files to Velocity -->
<servlet-mapping>
<servlet-name>velocity</servlet-name>
<url-pattern>*.vm</url-pattern>
</servlet-mapping>
</web-app>
附加问题。我从lib文件夹中删除了jar,并将它们添加到我的class-path中。它抛出了一堆错误。我可以在外部指向所有的Velocity Jar文件,还是需要将它们导入到我的项目的lib文件夹中才能使用?谢谢! – worked 2012-02-20 17:10:35
嘿,你能提供一个你的速度项目的例子吗?我想成立一个,但我有困难。你能否分享你的项目文件夹,以便我可以看到文件的位置? 谢谢! – deucalion0 2012-05-02 22:50:11