简体   繁体   English

NetBeans模板脚本

[英]NetBeans Template Scripting

In NetBeans you can create class templates. 在NetBeans中,您可以创建类模板。 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. 如您所见,这只是一个包含ESAPI记录器的简单模板,现在我要做的是检查ESAPI.class是否存在,然后仅应创建记录器,否则应创建其他记录器,比如说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: 感谢Joop Eggen的评论,我将使用变量Route:

You can set variables (like choosing another value for ${user}). 您可以设置变量(例如为$ {user}选择另一个值)。 and use <#if>. 并使用<#if>。 An internet search for changing the user in NB will point to the direction. 在NB中更改用户的互联网搜索将指向该方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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