Questions tagged [velocity]

Apache Velocity is a Java-based template engine. It can be used to dynamically generate web pages, email messages, source code, or any other text file.

Apache Velocity is a Java-based template engine. It can be used to dynamically generate web pages, email messages, source code, or any other text file.

Apache Velocity is a project of the Apache Software Foundations (ASF).

More information is available at the project home page: http://velocity.apache.org.

From the developer perspective, the fundamental pattern for rendering a text file is:

  • Create and initialize a VelocityEngine.
  • Add your data objects to a Context (essentially, a map of objects available for use in the template)
  • Choose a template
  • Merge the template with the context.

This can be done in a few lines of Java code, or you can use one of several frameworks to integrate this with your application.

One of the most popular web application frameworks which integrates Velocity is the Spring Framework. For simple servlet based applications, most developers use one of the Velocity Tools servlets (also available from the Apache Velocity project).

Useful Online Resources

  1. Velocity User Guide
  2. Velocity Developer Guide
2370 questions
19
votes
6 answers

Error in velocity and log4J

I built a webapp that works perfectly fine in my localhost (tomcat). But when I tried to deploy, velocity crashes in init(), leaving me with this strange stack trace here (sorry for the size): ERROR [main] (VelocityConfigurator.java:62) - Error…
José Leal
  • 7,989
  • 9
  • 35
  • 54
19
votes
2 answers

Where does Velocity search for the template?

I need to use Velocity from Java-code in a web-application (I use it as mail-templates processor). So, I have a standard code: VelocityEngine ve = new VelocityEngine (); try { ve.init (); Template t = ve.getTemplate (templatePath); ... }…
Roman
  • 64,384
  • 92
  • 238
  • 332
19
votes
3 answers

How do you insert the current year into IntelliJ IDEA Copyright template?

I'm trying to make an Apache Velocity template for MIT license in IntelliJ IDEA copyright settings. I want it to print 2015-${current_year} where the year is. Here is what I've tried to put in Settings → Copyright → Copyright Profiles → MIT →…
gvlasov
  • 18,638
  • 21
  • 74
  • 110
19
votes
4 answers

Velocity editor plugin for Eclipse Luna

I was searching for a Velocity editor plugin for Eclipse Luna but I could not find any. I found couple of editor plugins like: Veloeclipse Velocity Editor Veloedit <--------------- This is now working on Luna 4.4.1! QIQU Velocity Web…
Aksiom
  • 1,565
  • 4
  • 25
  • 39
19
votes
6 answers

Is Apache Velocity still an active project?

Seeing that Velocity's latest stable version was released at least two years ago, I was hoping the good people at SF would be able to suggest if this project is still actively maintained. I can see no hint to this other then a Velocity 2.0 project…
Nir Levy
  • 4,613
  • 2
  • 34
  • 47
19
votes
4 answers

Escaping the dollar sign in velocity using backslash not working

I have the following segment to get rendered from a velocity template file. xyz $$foo The dollar signs need to be escaped from VTL parser. And in the template file I represented it as xyz \$\$foo I expect xyz $$foo but I get xyz \$foo What am I…
Abinash Koirala
  • 977
  • 1
  • 9
  • 18
18
votes
7 answers

How to format Numbers in Velocity Templates?

I am getting a java object in my velocity template. The object has a double value which I want to format to 2 decimal places and display it in my template. The class for which im getting an object is something like this Class Price { double…
Rajesh Pantula
  • 10,061
  • 9
  • 43
  • 52
18
votes
7 answers

Velocity Templates - New Line

I've been working with Apache's Velocity engine and a custom template. The thing is, that I haven't been able to generate a String with the corresponding line breaks. I tried almost everything that I found, such as using $esc.n and $esc.newline (I'm…
LdSe
  • 334
  • 1
  • 3
  • 17
18
votes
5 answers

Velocity can't find resource

Something is wrong and it is very frustrating. I read on velocity's homepage that when I run a webapp then some properties should be set. And I've done that but no matter what I do I keep getting the same error. This is where I set the props and…
AnAmuser
  • 1,885
  • 5
  • 26
  • 42
18
votes
1 answer

Meteor Velocity with Jasmine not returning expecting result?

I'm trying to test the following which works manually: Return a list of users as
's Click a button to reduce that count of
's by one. This does not seem to be working: it("should show one less person if you tap you liked them",…
Daniel Fischer
  • 3,042
  • 1
  • 26
  • 49
18
votes
3 answers

Can I convert an artifactId to a classname prefix in my maven archetype?

I'm creating a maven archetype and in the projects generated a want a class that is named after the artifact id of the generated project. The artifact id will be formatted like: the-project-name and the class should be named TheProjectNameMain. I've…
Bob Brinks
  • 1,372
  • 1
  • 10
  • 19
18
votes
4 answers

How to select the format of $date in vm file?

I have a $date defined as "day of week, month day, year" ex: Tuesday, February 26, 2013 I don't know where $date is defined but I like to add the hour to this $date variable, or create a variable with the hour, do you know how can I put it in the…
aF.
  • 64,980
  • 43
  • 135
  • 198
17
votes
3 answers

how to plot streamlines , when i know u and v components of velocity(numpy 2d arrays), using a plotting program in python?

i hope the title itself was quite clear , i am solving 2D lid-driven cavity(square domain) problem using fractional step method , finite difference formulation (Navier-Stokes primitive variable form) , i have got u and v components of velocity over…
fedvasu
  • 1,232
  • 3
  • 18
  • 38
17
votes
1 answer

Lowercase first letter in Apache Velocity

I've got this code, which converts "dotted" string to camelCase in WebStorm File Template: #set($Controller_name = ${StringUtils.removeAndHump(${NAME}, ".")}) For example it converts foo.bar.test to FooBarTest. But what I need is to convert it from…
zorza
  • 2,814
  • 3
  • 27
  • 41
16
votes
3 answers

How to set properly the loader path of velocity

i would like that my velocityengine look for templates from a designed path. i did this :
storm_buster
  • 7,362
  • 18
  • 53
  • 75