简体   繁体   中英

Auto document time of creation of new Java class

When I create a new Java file in NetBeans, I get auto documentation for @author . How can I setup NetBeans that is also documents the time and date of creation of the class?

I know NetBeans can do it as I get the time and date of creation in new CSS files by default.

You can change the template files in Netbeans. Go to Tools|Templates . From the available templates, find the one you want to change, let's say Java|Java Class , then select Open in Editor

Then goto to FaqTemplateVariables for list of available template variables. In your case, you're looking for ${date} and {$time}

Then you modify the template the way want, for example...

<#assign licenseFirst = "/*">
<#assign licensePrefix = " * ">
<#assign licenseLast = " */">
<#include "${project.licensePath}">

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

</#if>
/**
 *
 * @author ${user}
 * ${date} ${time}
 */
public class ${name} {

}

Then simple create a new "Java Class" - File|New File|Java|Class and it should then generate a file similar to this...

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package my.awesome.library;

/**
 *
 * @author noob
 * 25/06/2017 3:19:39 PM
 */
public class Test {

}

Now, you'll probably have to go through a number of the other templates and update them, but that gives you a place to start

@MadProgrammer answered well. Just in case as an addition to this answer. U can optionally add properties in the User.properties file which is read by the various templates in the Tools -> Templated ->* configs . So if u want to add version to your Java classes . you can define the @version in the Java class template and then define the property in the User.properties file as in the following

In Your Java class template

....
 /**
  * ${date} ${time}
  * ${version}
  * ...other 
  */

U can then set these properties in the User.properties file as

  version=1.0.0

etc

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