README.md
1# Welcome to Velocity!
2
3This package contains a few examples to help get you started.
4
5As always, the if you have any questions :
6
71. Make sure you followed any directions :-) (did you build
8 everything?)
9
102. Review documentation included in this package, or online at
11 [https://velocity.apache.org/](https://velocity.apache.org/)
12
133. Ask on the [velocity-user list](https://velocity.apache.org/contact.html#user).
14 This is a great source of support information. To join, read the
15 [contact page](https://velocity.apache.org/contact.html) and then follow the links to join the lists.
16
17## Building from sources
18
19To 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
21The archive contains a `build.sh` script which you can use to re-build the examples after tweaking the sources in the `src` directory.
22
23## Running the examples
24
25Once 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
27Note 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
29Finally, 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
31 https://velocity.apache.org/tools/
32
33# Velocity Examples
34
35## Application Example #1
36
37This simple example shows how to use the Velocity Template Engine
38in a standalone program. It should be pre-compiled for you. Run it using the example
39template provided (`example.vm`):
40
41 ./example1.sh
42
43## Application Example #2
44
45Another simple example showing how to use Velocity in a standalone
46program. This examples uses the org.apache.velocity.util.Velocity application utility
47class, which provides a few convenient methods for application programmers. It also
48should be precompiled for you. To run:
49
50 ./example2.sh
51
52## Context Example
53
54This is a demonstration of 2 different context implementations:
55
56- 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
58- a context implementation that uses a `TreeMap` for storage. Very simple.
59
60To run:
61
62 ./dbcontexttest.sh
63
64## Xml App example
65
66This is simple example that demonstrates direct access of XML data via
67Velocity templates, as well as Velocimacro recursion. To run:
68
69 ./xmlapp_example.sh
70
71## Event Example
72
73This is a simple yet more advanced example, and shows how to use the event handling
74features of Velocity. This is an advanced topic, so if you are just
75starting with Velocity, you can come back to it later. To run:
76
77 ./event_example.sh
78
79___
80
81Thanks for using Velocity!
82
83>the Velocity team
84