在Eclipse中为新建java文件自动添加文件头
2011-07-08 16:53
537 查看
1. 打开菜单:"Window->Preferences->Java->Code Style->Code Templates",在右侧可以配置代码和注释的格式;
2. 选择其中的"Code->New Java files", 在"Pattern:"文本框中可以看到如下内容:
${filecomment}
${package_declaration}
${typecomment}
${type_declaration}
这4个都是变量,我最关心的是$(filecomment),如何知道这个变量代表什么内容呢?这一点Eclipse做的不好,没有在明显的地方的说明,不过你可以按照如下操作找到各个变量代表的实际内容:在"Configure generated code and comments"文本框中随便选中一项,比如选择"New Java files",点击“Edit...”,在出现的对话框中选择"Insert Variable..."会出现一个下拉菜单,其中每个变量都在右侧有个浮动的窗口显示其内容说明。
3. 我想在${filecomment}中配置文件头的内容,因此根据该变量的内容提示,找到真正的编辑位置为"Comments->Files",编辑其中的内容,使其符合我的需要,比如我编辑的文件头如下:
/**
* Filename : ${file_name}
* Author : xxxxxxx
* Creation time : ${time} - ${date}
* Description :
*/
其中${file_name},${time} ,${date}都是eclipse的内置变量
4. 最后使定制的文件头生效,勾选页面下方的"Automatically add comments for new methods and types"(老版Eclipse的这个选项在上一层菜单中:"Code Style")
2. 选择其中的"Code->New Java files", 在"Pattern:"文本框中可以看到如下内容:
${filecomment}
${package_declaration}
${typecomment}
${type_declaration}
这4个都是变量,我最关心的是$(filecomment),如何知道这个变量代表什么内容呢?这一点Eclipse做的不好,没有在明显的地方的说明,不过你可以按照如下操作找到各个变量代表的实际内容:在"Configure generated code and comments"文本框中随便选中一项,比如选择"New Java files",点击“Edit...”,在出现的对话框中选择"Insert Variable..."会出现一个下拉菜单,其中每个变量都在右侧有个浮动的窗口显示其内容说明。
3. 我想在${filecomment}中配置文件头的内容,因此根据该变量的内容提示,找到真正的编辑位置为"Comments->Files",编辑其中的内容,使其符合我的需要,比如我编辑的文件头如下:
/**
* Filename : ${file_name}
* Author : xxxxxxx
* Creation time : ${time} - ${date}
* Description :
*/
其中${file_name},${time} ,${date}都是eclipse的内置变量
4. 最后使定制的文件头生效,勾选页面下方的"Automatically add comments for new methods and types"(老版Eclipse的这个选项在上一层菜单中:"Code Style")
相关文章推荐
- sublime 设置新建文件自动添加author(作者)等文件头信息
- eclipse 新建 java 文件时自动生成注释
- eclipse 新建 java 文件时自动生成注释
- eclipse 新建java文件自动加作者,日期注释设置
- eclipse 导入工程时,有时会在一些package下自动添加defautl package并把java 文件放到其目录下。
- 如何在Eclipse中添加新建包,java文件,工程工具栏按钮
- 用eclipse新建一个android工程无法自动生成R.java文件
- eclipse 新建 java 文件时自动生成注释
- eclipse 新建 java 文件时自动生成注释
- 【Java】Eclipse新建的Java文件自动生成主函数、控制台输出行数不再受限制
- eclipse 新建 java 文件时自动生成注释
- Eclipse和Android Studio新建文件时自动添加注释
- eclipse新建java文件时自动生成注释
- eclipse不能自动编译java文件的问题
- 【Javaweb】Eclipse for JavaEE新建的Web工程自动生成web.xml
- eclipse新建maven工程却没有自动建立src/main/java资源解决办法
- Android+Eclipse+JNI+javah 自动生成.h文件
- Eclipse添加DTD文件实现xml的自动提示功能
- eclipse新建maven webapp后无法添加src/main/java和src/main/test
- eclipse新建maven webapp后无法添加src/main/java和src/main/t