2012-02-20 74 views
2

Appache Velocity的新手,并试图在Eclipse中运行我的第一个虚拟页面(没有成功)。这里是我到目前为止所采取的步骤:Eclipse + Apache Velocity Engine?

  1. 下载速度引擎分布:http://velocity.apache.org/download.cgi#Engine
  2. 创建动态Web项目在Eclipse
  3. 选择Tomcat作为服务器
  4. 创建一个简单的索引。 vm文件
  5. 将velocity-1.7.zip中的所有jar文件添加到我的项目ClassPath中
  6. 运行index.vm,输出所有VTL(不是“vm-ized”)。

index.vm:

<html> 
<body> 
#set($foo = "Velocity") 
Hello $foo World! 
</body> 
<html> 

任何帮助,不胜感激!

回答

1

好吧,它在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> 
+1

附加问题。我从lib文件夹中删除了jar,并将它们添加到我的class-path中。它抛出了一堆错误。我可以在外部指向所有的Velocity Jar文件,还是需要将它们导入到我的项目的lib文件夹中才能使用?谢谢! – worked 2012-02-20 17:10:35

+0

嘿,你能提供一个你的速度项目的例子吗?我想成立一​​个,但我有困难。你能否分享你的项目文件夹,以便我可以看到文件的位置? 谢谢! – deucalion0 2012-05-02 22:50:11