简体   繁体   中英

Freemarker template for Java Netbeans that prints the date is was last modified in the class?

So I am learning to make a general template for java. So in Netbeans I went to the Tools menu and opened the Templates Manager and Opened the Java Class Template. This is what I did:

<#if package?? && package != "">
package ${package};

</#if>
/**
 *
 * Author: ${user}
 * Created : ${time} ${date}
 * Last Modified : ${lastUpdated}
 */
public class ${name} {

}

And the output is this:

package Maths;

/**
 *
 * Author: Emanuel Parkman
 * Created : 3:40:29 AM May 22, 2014
 * Last Modified : Expression lastUpdated is undefined on line 9, column 22 in Templates/Classes/Class.java.
 */
public class NewClass {

}

But when I look at the Freemarker Website : http://freemarker.org/docs/ref_builtins_date.html#ref_builtin_date_datetype

${lastUpdated}

Is used as one of the built-ins... I just want my comments to show when the java file was last saved. Is that possible? and if so, how?

You misunderstand the manual there. lastUpdated is not a built-in variable in FreeMarker. All the variables that you are using, like name , package , time , are provided by NetBeans. After all, FreeMarker is not specialized on generating source code (in fact, it's much more often used for generating Web pages). So check what variables are available in the NetBean documentation. Or, maybe try to list the available variables, like described here: does freemarker support show all variable in data-model?

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