Many of our developers wish to use IDE's such as Eclipse or IntelliJ IDEA for building and debugging Velocity.

However, Velocity has a quirky build process which makes it difficult to run the JUnit tests directly within your IDE. All Velocity files are copied to a temporary build directory before compiling. A filter is run on the test source files which substitute in an absolute path for the test templates before compiling. In particular, org.apache.velocity.test.TemplateTestBase is modified to include tese paths. This means that you will not be able to run JUnit in your IDE on the primary source files.

The trick to making this work is to use the original source for all files exept the one that contains the modified path. (Credit to Henning for originally figuring this out). Here's how to set this up.

(1) Run "ant prepare" to create the alternate source.

(2) Configure the Velocity project in your IDE to use two source trees: (a) the standard Java files in velocity\src\java and (b) the single file velocity\trunk\bin\test-src\org\apache\velocity\test\TemplateTestBase

(3) Generally, I set the directory for the compiled classes to be different that that generated by the ant tasks, e.g. bin\classes-ide

You should now be able to go to the test directory and run any JUnit test directly from your IDE.

Questions? Email the velocity development list at dev@velocity.apache.org .

  • No labels