Skip to content
Jörg Hohwiller edited this page Apr 21, 2015 · 4 revisions

eclipse-templatevariables

This is a plugin for Eclipse that provides additional template variables to JDT code templates.

Features

With this plugin you can use additional variables in your JDT code templates (e.g. Window > Preferences > Java > Code Style > Templates > Code Templates).

For maven project using m2e the following variables are resolved from pom.xml:

  • ${project_version} refers to the current version of your m2e project but excluding any -SNAPSHOT.

  • ${project_artifactId} refers to the current project artifactId of your m2e project.

  • ${project_name} refers to the current project name of your m2e project.

The most common use-case is to add the following to the JavaDoc of your type-comment:

@since ${project_version}

So new types created with Eclipse automatically carry the version of your project that introduced the new type.

Further, eclipse already provides the ability to define and manage key/value pairs in Window > Preferences > Run/Debug > String Substituion. This plugins makes these key/value pairs available as variables so you can use them in JDT code templates.

So you can e.g. define the variable author with the value you like to have. Then you can use ${author} instead of ${user}. Instead of tweaking the system properties and faking your user.name what is actually a bad hack you can now just change the value of author in the preferences. Simply change your code-templates to use this line:

@author ${author}

Installation

Advanced users will only need the Update Site.

  1. From the Menu select Help > Install New Software...

  2. Click on the Add button

  3. Enter templatevariables for Name

  4. Enter https://m-m-m.github.io/eclipse-templatevariables/latest for Location

  5. Confirm with OK button

  6. Wait a moment (ensure templatevariables is entered for Work with)

  7. In the selection area expand mmm Tools and check mmm-TemplateVariables

  8. Click on Next

  9. Click on Next again

  10. You need to read and confirm the license agreement

  11. Then click on Finish

  12. Wait a while

  13. Confirm the security warning about unsigned content with OK

  14. Confirm to restart Eclipse with Yes

  15. Wait until eclipse is restarted

  16. Enjoy the new plugin

Clone this wiki locally