Eclipse + Apache 速度引擎?

标签 eclipse tomcat jar virtual-machine velocity

Appache Velocity 的新手并尝试在 Eclipse 中运行我的第一个 vm 页面(没有成功)。以下是我目前采取的步骤:

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

index.vm:

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

非常感谢任何帮助!

最佳答案

好的,让它在 Eclipse 中运行。只需将所有 Velocity Jar 文件添加到我的动态 Web 项目中 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>

关于Eclipse + Apache 速度引擎?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9363643/

相关文章:

eclipse - 打印边距卡在 Eclipse 中

tomcat - 在同一个 ios 上运行 2 个 tomcat 实例

java - 如何使用根目录的相对路径来生成 JAR 文件?

在使用 1.6 jdk 编译的项目中运行 jdk 1.7 编译的 jarfile 时出现 java.lang.NoClassDefFoundError

java - 为什么 java 提示 jar 文件有很多条目?

eclipse - 我们如何在STS中查看Grails框架的来源?

java - Maven 依赖项在 WEB-INF/lib 中不可见

java - 在eclipse中安装maven

java - 防止数据库更新期间 session 超时

tomcat - 索引更新时 OpenGrok 主页不刷新