如何在 Eclipse 中自动向源文件添加默认标头?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2604424/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 19:19:01  来源:igfitidea点击:

How can I add a default header to my source files automatically in Eclipse?

eclipseeclipse-plugin

提问by John

I'm trying to figure out how I can have a comment header automatically added to all new source files in my eclipse java project. I've looked around but I haven't found a simple solution to automate this process. I gave JAutodoc a try, and even though it does allow me to specify a header I still had to tell the plugin manually to inject the header and it didn't seem very fond of my keyword-subsitution.

我试图弄清楚如何将注释标题自动添加到我的 eclipse java 项目中的所有新源文件中。我环顾四周,但没有找到一个简单的解决方案来自动化这个过程。我尝试了 JAutodoc,尽管它允许我指定标题,但我仍然必须手动告诉插件注入标题,而且它似乎不太喜欢我的关键字替换。

I'm by the way using the Maven2 plugin for Eclipse for most of my projects if that's any help.

顺便说一下,如果有帮助的话,我正在为我的大多数项目使用 Eclipse 的 Maven2 插件。

Any tips?

有小费吗?

回答by Gabriel ??erbák

Comments generation is configured in:

评论生成配置在:

Main Menu-> Window-> Preferences-> Java-> Code Style-> Code Templates-> Configure generated code and comments

主菜单->窗口->首选项-> Java->代码样式->代码模板->配置生成的代码和注释

You can change directly the New Java files template: Code-> New Java files-> Edit

您可以直接更改新 Java 文件模板: 代码->新 Java 文件->编辑

As of Eclipse 3.6 version, it is already configured that for new Java files ${filecomment}is inserted, so it is probably better to edit it instead:

从 Eclipse 3.6 版本开始,它已经配置${filecomment}为插入新的 Java 文件,因此最好对其进行编辑:

Comments-> Files-> Edit

评论->文件->编辑

回答by Jmini

If you want to add your comment a the top of the file (to add a copyright header), give a try to Eclipse Copyright Generator. There is a wizard that ask you what you want to include. Therefore you can add every kind of comment header.

如果您想将您的评论添加到文件的顶部(以添加版权标题),请尝试Eclipse Copyright Generator。有一个向导会询问您要包含的内容。因此,您可以添加各种评论标题。

After installation you get a new menu: Project > Apply Copyright....

安装完成后你会得到一个新的菜单:项目>应用版权所有...

In the include filesfield enter *.javato reduce the set of files.

包含文件字段中输入*.java以减少文件集。

see also this answer

另见这个答案



As indicated in the comments, there is an other tool provided by the Eclipse Fundation: Eclipse Copyright Tool(as part of their releng tools)

正如评论中所指出的,EclipseFundation 还提供了另一个工具:Eclipse Copyright Tool(作为其 releng 工具的一部分)