netbeans自定义文件模板(备忘)

netbeans自定义文件模板(备忘)

本文以windows下自定义PHP文件模板为例。
点击顶部菜单:
Tools-> Templates ,

如编辑PHP模板,内容如下:

1
2
3
4
5
6
7
8
9
10
11
12

<?php
/**
 * @filename ${nameAndExt}
 * @encoding ${encoding}
 * @author  ${author}
 * @link  ${link}
 * @copyright  ${copyright}
 * @license http://www.gnu.org/licenses/
 * @datetime ${date}  ${time}
 * @version 1.0
 * @Description
  */

如果要加上许可证,则可用如下方式:

1
2
3
4

<#assign licenseFirst = "/**">
<#assign licensePrefix = " * ">
<#assign licenseLast = " */">
<#include "../Licenses/license-${project.license}.txt">

既然上面指定了许可证的位置,那么得让许可证存在,要不然会抛出异常。

1
2

cd C:\Users\HuangYe\.netbeans\7.0\config\Templates
mkdir Licenses

以添加GPL许可证为例,在Template Manager 窗口中,选择 Licenses,再选择默认的DefaultLicense ,点击“Duplicate”复制一份,然后重命名为
license-gpl.txt (如果不这样做,而是直接在目录中新建文件的话,这个管理器里面是不可见的,不便于管理)


然后编辑之,内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

<#if licenseFirst??>
${licenseFirst}
</#if>
${licensePrefix} Copyright (C) <2011>  <荒野无灯>

${licensePrefix} This program is free software: you can redistribute it and/or modify
${licensePrefix} it under the terms of the GNU General Public License as published by
${licensePrefix} the Free Software Foundation, either version 3 of the License, or
${licensePrefix} (at your option) any later version.

${licensePrefix} This program is distributed in the hope that it will be useful,
${licensePrefix} but WITHOUT ANY WARRANTY; without even the implied warranty of
${licensePrefix} MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
${licensePrefix} GNU General Public License for more details.

${licensePrefix} You should have received a copy of the GNU General Public License
${licensePrefix} along with this program.  If not, see <http://www.gnu.org/licenses/>.
<#if licenseLast??>
${licenseLast}
</#if>

至于要在项目中使用哪个许可证,要在项目目录下的nbproject/project.properties 文件中定义,如:

1

project.license=gpl

在nb模板中,我们可以使用 FreeMarker 模板语言,如下是一些预定义的变量:

${date} 插入眼前日期,格式如: Feb 16, 2008
${encoding} 插入默认编码,如: UTF-8
${name} 插入文件名
${nameAndExt} 插入带扩展名的文件名
${package} inserts the name of the package where the file is created.
${time} 插入当前时间,如: 7:37:58 PM
${user} 插入用户名

我们也可以自定义一些量,Tools-> Templates -> Settings ,这里nb会为你打开User.properties 文件(在windows7下这个文件的位置是C:\Users\HuangYe\.netbeans\7.0\config\Templates\Properties\User.properties,如这是我的定义:

1
2
3

author=荒野无灯 <HuangYeWuDeng, admin@ihacklog.com>
copyright=Copyright (C) 2011 荒野无灯
link=http://ihacklog.com


转载于:https://my.oschina.net/jiangchike/blog/528888

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值