xref: /aosp_15_r20/external/apache-velocity-engine/velocity-engine-examples/README.md (revision 6626518d3d1a3a4cd21045b7974855fd6a3e2103)
1*6626518dSAndrew Vuong# Welcome to Velocity!
2*6626518dSAndrew Vuong
3*6626518dSAndrew VuongThis package contains a few examples to help get you started.
4*6626518dSAndrew Vuong
5*6626518dSAndrew VuongAs always, the if you have any questions :
6*6626518dSAndrew Vuong
7*6626518dSAndrew Vuong1. Make sure you followed any directions :-) (did you build
8*6626518dSAndrew Vuong   everything?)
9*6626518dSAndrew Vuong
10*6626518dSAndrew Vuong2. Review documentation included in this package, or online at
11*6626518dSAndrew Vuong   [https://velocity.apache.org/](https://velocity.apache.org/)
12*6626518dSAndrew Vuong
13*6626518dSAndrew Vuong3. Ask on the [velocity-user list](https://velocity.apache.org/contact.html#user).
14*6626518dSAndrew Vuong   This is a great source of support information.  To join, read the
15*6626518dSAndrew Vuong   [contact page](https://velocity.apache.org/contact.html) and then follow the links to join the lists.
16*6626518dSAndrew Vuong
17*6626518dSAndrew Vuong## Building from sources
18*6626518dSAndrew Vuong
19*6626518dSAndrew VuongTo build these examples from Velocity sources, please refer to the [Velocity build page](https://velocity.apache.org/engine/${project.version}/build.html). The build will generate the zip archive target/${project.build.finalName}-pkg.zip containing all the examples.
20*6626518dSAndrew Vuong
21*6626518dSAndrew VuongThe archive contains a `build.sh` script which you can use to re-build the examples after tweaking the sources in the `src` directory.
22*6626518dSAndrew Vuong
23*6626518dSAndrew Vuong## Running the examples
24*6626518dSAndrew Vuong
25*6626518dSAndrew VuongOnce you have downloaded or sucessfully built the ${project.build.finalName}-pkg.zip downloaded package, unzip it in the location of your choice and change to the ${project.build.finalName} directory.
26*6626518dSAndrew Vuong
27*6626518dSAndrew VuongNote for Windows users: the shell scripts used to running the examples are meant for linux or BSD, but can easily be adapted as batch files. all they do is build the classpath from the jars in the lib/ directory, then invoke Java on the main class with the adequate arguments.
28*6626518dSAndrew Vuong
29*6626518dSAndrew VuongFinally, note that more examples of using Velocity can be found in the velocity-tools subject.  Of special note is the VelocityViewServlet, a quick and easy way to build a web application that uses Velocity.
30*6626518dSAndrew Vuong
31*6626518dSAndrew Vuong   https://velocity.apache.org/tools/
32*6626518dSAndrew Vuong
33*6626518dSAndrew Vuong# Velocity Examples
34*6626518dSAndrew Vuong
35*6626518dSAndrew Vuong## Application Example #1
36*6626518dSAndrew Vuong
37*6626518dSAndrew VuongThis simple example shows how to use the Velocity Template Engine
38*6626518dSAndrew Vuongin a standalone program.  It should be pre-compiled for you. Run it using the example
39*6626518dSAndrew Vuongtemplate provided (`example.vm`):
40*6626518dSAndrew Vuong
41*6626518dSAndrew Vuong    ./example1.sh
42*6626518dSAndrew Vuong
43*6626518dSAndrew Vuong## Application Example #2
44*6626518dSAndrew Vuong
45*6626518dSAndrew VuongAnother simple example showing how to use Velocity in a standalone
46*6626518dSAndrew Vuongprogram.  This examples uses the org.apache.velocity.util.Velocity application utility
47*6626518dSAndrew Vuongclass, which provides a few convenient methods for application programmers.  It also
48*6626518dSAndrew Vuongshould be precompiled for you.  To run:
49*6626518dSAndrew Vuong
50*6626518dSAndrew Vuong    ./example2.sh
51*6626518dSAndrew Vuong
52*6626518dSAndrew Vuong## Context Example
53*6626518dSAndrew Vuong
54*6626518dSAndrew VuongThis is a demonstration of 2 different context implementations:
55*6626518dSAndrew Vuong
56*6626518dSAndrew Vuong- a context implementation that uses a database as the storage. You will need to copy the appropriate JDBC driver jar file in the lib/ directory, and to adapt the JDBC driver and credentials accordingly in the `src/org/apache/velocity/example/DBContextTest.java` file.
57*6626518dSAndrew Vuong
58*6626518dSAndrew Vuong- a context implementation that uses a `TreeMap` for storage.  Very simple.
59*6626518dSAndrew Vuong
60*6626518dSAndrew VuongTo run:
61*6626518dSAndrew Vuong
62*6626518dSAndrew Vuong    ./dbcontexttest.sh
63*6626518dSAndrew Vuong
64*6626518dSAndrew Vuong## Xml App example
65*6626518dSAndrew Vuong
66*6626518dSAndrew VuongThis is simple example that demonstrates direct access of XML data via
67*6626518dSAndrew VuongVelocity templates, as well as Velocimacro recursion. To run:
68*6626518dSAndrew Vuong
69*6626518dSAndrew Vuong    ./xmlapp_example.sh
70*6626518dSAndrew Vuong
71*6626518dSAndrew Vuong## Event Example
72*6626518dSAndrew Vuong
73*6626518dSAndrew VuongThis is a simple yet more advanced example, and shows how to use the event handling
74*6626518dSAndrew Vuongfeatures of Velocity.  This is an advanced topic, so if you are just
75*6626518dSAndrew Vuongstarting with Velocity, you can come back to it later. To run:
76*6626518dSAndrew Vuong
77*6626518dSAndrew Vuong    ./event_example.sh
78*6626518dSAndrew Vuong
79*6626518dSAndrew Vuong___
80*6626518dSAndrew Vuong
81*6626518dSAndrew VuongThanks for using Velocity!
82*6626518dSAndrew Vuong
83*6626518dSAndrew Vuong>the Velocity team
84