I have a maven archetype project. When I use this archetype I want that some files report the actual date. I tried with $date but Velocity does not recognize it. I found something called DateTools but I don't know how can I use it. It's the first time I use Velocity.
相关问题
- Maven Repositories for Spring Roo
- Velocity Unable To find Resources
- What is the best way to externalize properties in
- Export Maven dependencies and maintain repository
- speed or acceleration of motion event android
相关文章
- Getting velocity error at statup “VM_global_librar
- Find Java options used by Maven
- Send Maven output to console and log file using po
- Is there a way to debug Velocity templates in the
- How to disable velocity logs
- Velocity templates seem to fail with UTF-8
- Better way to use Velocity's GenericTools in a
- dependencyManagement in parent ignored
(Apologies for resurrecting an old question, but I have just worked through a way to achieve this without the need to pull and patch the plugin).
For anyone that wants to be able to reference date fields in their maven archetype templates, I was able to get it working with the following set of definitions at the top of my pom.xml template
If you already have object based variables available to your template at the point that you insert those lines, you can scratch the $str declaration and use one of your variables instead as it doesn't really matter where you get the reference to Class.forName() from.
NOTE: My attempts to get this working with Calendar.getInstance() were unsuccessful.
Unfortunately, the Maven Archetype plugin doesn't come bundled with Velocity Tools. I've added it by modifying the Maven Archetypes Plugin. Follow these steps, presuming you're using Maven 2.2.1:
The modified Maven Archetype plugin will now be installed locally.
$date
usage in your templates should now render, e.g....to:
In Java 8, with a formatter:
I managed to trim down the solution from @maaxiim to a single line:
The $package variable will always be available from the maven archetype plugin. The other builtins work as well, but most of them are quite long, and $artifactId.getClass() just looks... wrong.