2013-02-19 91 views
3

我有代碼風格模板,它爲新的Java類定義了帶有註釋的默認註釋(見下文)。
如何讓它插入Maven的版本pom.xml? 喜歡的東西如何在Eclipse代碼模板中獲取Maven pom.xml版本?

@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> 

回答

2

要做到你的要求,就必須是一個Eclipse插件提供的變量的代碼模板。在Can you define your own template variables in eclipse的答案中有一些這類插件信息的鏈接。你可以從m2e項目中輸入request this as a feature

更快的解決方案是朝另一個方向前進:不是讓Eclipse從Maven獲取信息,而是讓Maven寫入數據。有一些很好的說明Using Maven to output the version number to a text file

+0

該文件已經作爲標準存在META-INF \ MANIFEST.MF – 2013-03-11 03:22:40

+0

而不是非標準文本文件,最好使用META-INF \ MANIFEST.MF。 (可以通過mvn war:manifest輕鬆創建)但是,Eclipse IDE中不支持讀取代碼內部模板。 – 2013-03-11 03:34:48

相關問題