简体   繁体   中英

NetBeans Template Scripting

In NetBeans you can create class templates. The following template is what i have created so far. I would like to make a small improvement but i don't know if it would be possible.

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

</#if>
import org.owasp.esapi.ESAPI;
import org.owasp.esapi.Logger;

/**
 *
 * <#if package?? && package != "">${package}.${name}</#if>
 * @author ${user}
 * @createdDate ${date}
 */

public class ${name} {

    private static final Logger LOG = ESAPI.getLogger(${name}.class);
}

As you can see it is just a simple template that incldes a ESAPI logger, now what i want to do is check if ESAPI.class exists and then only should the logger created, otherwise a different Logger should be created, lets say Log4J.

the Reason i want to do this is i am working on many projects and i don't want to create a class template for each project, if it comes down to it i will, but i thought one of you might know if it was possible.

Thanks to Joop Eggen's comment, i will go the variable Route:

You can set variables (like choosing another value for ${user}). and use <#if>. An internet search for changing the user in NB will point to the direction.

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