如何安装和使用Apache Velocity? [英] How do I install and use Apache Velocity?

查看:351
本文介绍了如何安装和使用Apache Velocity?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了Apache服务器2.4和Ant 1.8.3,已经下载了Velocity 1.7和Velocity工具2.0.我已经阅读了十次有关Apache Velocity的安装文档,并用Google搜索了两天,但我仍然不知道如何处理这些文件.谁能提供有关如何安装Velocity的详细说明?

I have installed Apache server 2.4, and Ant 1.8.3, I have downloaded Velocity 1.7, and Velocity tools 2.0. I have read the installation documentation for Apache Velocity about ten times, and Googled it for two days, I still have no idea what to do with these files. Can anyone provide a detailed description on how to install Velocity please?

我希望使用Eclipse进行开发,所以我也已经安装了它.

I was hoping to develop using Eclipse, so I have also installed this.

在遇到困难时,我将不胜感激.

I would appreciate any assistance as I am stuck.

谢谢.

更新:

我已经将Eclipse配置为使用Tomcat,并按照教程的方式进行了工作,并设法使所有这些工作正常进行,但是,如果有人使用Eclipse构建了Velocity,我不知道如何在Eclipse中准确启动速度项目.项目,我将对如何进行设置提供一些建议.

I have configured Eclipse to use Tomcat and have worked my way through a tutorial and managed to get this all working, but I do not know how exactly to start a velocity project in Eclipse, if anyone has used Eclipse to build a Velocity project, I would appreciate some advice on how to set that up.

谢谢.

推荐答案

您还将需要一个 Java EE容器(又名 servlet容器),例如Apache Tomcat. Apache HTTP服务器对Java一无所知.请注意,Tomcat本身可以直接用作HTTP服务器-通常,您会选择在生产服务器上将Apache HTTP服务器置于Tomcat的前面,以加快静态文件请求的速度(其他原因(Apache HTTP可以使用mod_proxy_ajp将请求转发至Tomcat)模块).但是从一开始,直接使用Tomcat提供的HTTP服务就更容易了.

You will also need a Java EE container (aka servlet container) like Apache Tomcat. The Apache HTTP server doesn't know anything about Java. Please note that Tomcat can itself be used directly as an HTTP server - you would typically choose to keep Apache HTTP server in front of Tomcat on production servers to speed up static files requests among other reasons (Apache HTTP can forward requests to Tomcat with the mod_proxy_ajp module). But for the beginning, it's easier to directly use the HTTP service provided by Tomcat.

然后,您需要熟悉 Web应用程序的概念.它只不过是特定的文件层次结构(可以将其压缩为扩展名为 .war 的jar文件).对于使用Velocity的Web应用程序,通常为:

Then, you need to get familiar with the concept of a Web Application. It's nothing more than a specific hierarchy of files (that can be compressed into a jar file with the .war extension). For a web application using Velocity, that would typically be:

./← 您的Web应用程序的根目录
./index.vhtml← 您的欢迎页面模板
./foo/bar.vhtml← 包含您的网络资源的任何其他文件或子目录
./WEB-INF/← WEB-INF目录包含所有Web应用程序配置
./WEB-INF/web.xml← 将HTTP请求映射到过滤器和servlet
./WEB-INF/tools.xml← Velocity自定义工具的可选配置文件
./WEB-INF/velocity.properties← 用于调整速度配置的可选文件
./WEB-INF/lib/← 包含您的Web应用程序所需的所有库
./WEB-INF/src/← 包含您的自定义Java类源代码
./WEB-INF/classes/← 包含您的自定义Java类

./ ← root of your web application
./index.vhtml ← your welcome page template
./foo/bar.vhtml ← any other file or subdirectory containing your web resources
./WEB-INF/ ← the WEB-INF directory contains all web application configuration
./WEB-INF/web.xml ← maps HTTP requests towards filters and servlets
./WEB-INF/tools.xml ← optional configuration file for your Velocity custom tools
./WEB-INF/velocity.properties ← optional file to tune Velocity configuration
./WEB-INF/lib/ ← contains all the libraries needed by your web application
./WEB-INF/src/ ← contains your custom Java classes source code
./WEB-INF/classes/ ← contains your custom Java classes

您的 web.xml 文件必须将足够的请求映射到VelocityViewServlet.看起来像这样:

Your web.xml file has to map adequate requests towards the VelocityViewServlet. It will look like this:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

  <servlet>
    <servlet-name>view</servlet-name>
    <servlet-class>org.apache.velocity.tools.view.VelocityViewServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>view</servlet-name>
    <url-pattern>*.vhtml</url-pattern>
  </servlet-mapping>

</web-app>

由于我不使用Eclipse,所以我不能为您提供很多帮助,但是如果您搜索tomcat + eclipse,似乎在线上有一些教程.这看起来很有趣:
http://www.coreservlets. com/Apache-Tomcat-Tutorial/tomcat-7-with-eclipse.html

I cannot help you much with Eclipse as I don't use it, but there seems to be several tutorials online if you search for tomcat + eclipse. Here's one that looks interesting:
http://www.coreservlets.com/Apache-Tomcat-Tutorial/tomcat-7-with-eclipse.html

这篇关于如何安装和使用Apache Velocity?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆