简体   繁体   中英

How to get Maven pom.xml version in Eclipse code template?

I have Code style template that defines default comments with annotations for new Java classes (see below).
How to make it insert the version from Maven pom.xml ? Something like

@since ${pom.project.version}

CodeStyle_codetemplates.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- 
Code Style Code Template 
To start using open Window -> Preferences
Java \ Code Style \ Code Template
Press [Import...] button and select this file.
 -->
<templates>
<template autoinsert="false" context="newtype_context" deleted="false" description="Newly created files" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.newtype" name="newtype">${filecomment}
${package_declaration}

/**
 * 
 * @since ${date}
 * @author ${user} 
 * Reviewer 
 */
${typecomment}
${type_declaration}</template></templates>

To do what you're asking, there would need to be an Eclipse plugin to provide the variables to the code template. There are some links to information on this type of plugin in the answers to Can you define your own template variables in eclipse . You could request this as a feature from the m2e project.

A faster solution would be to go in the other direction: instead of having Eclipse pull information from Maven, have Maven write the data. There are some good instructions in Using Maven to output the version number to a text file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM