eclipse 在eclipse中为所有源文件添加标准注释头

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4105664/
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:43:36  来源:igfitidea点击:

Adding a standard comment header to all source files in eclipse

eclipse

提问by jax

Is there a way to add a standard header comment in one place and it will apply to all my source files in my project? the header would contain my name, contact details, company, license etc.

有没有办法在一个地方添加标准标题注释,它会应用于我项目中的所有源文件?标题将包含我的姓名、联系方式、公司、许可证等。

采纳答案by Jmini

If you are looking for a tool with a good Eclipse integration (and a nice GUI), I suggest: Eclipse Copyright Generator

如果您正在寻找具有良好 Eclipse 集成(和漂亮的 GUI)的工具,我建议:Eclipse Copyright Generator

This adds:

这补充说:

  • a new Panel in the preferences (global or project based) with: Menu > Windows > Preferences > General > Copyright.
  • a Menu Menu > Project > Apply Copyright...
  • a realy nice Wizard with a lot of options and some default template for Open-Source licence (Apache, EPL, ...)
  • 首选项(基于全局或​​项目)中的一个新面板: Menu > Windows > Preferences > General > Copyright
  • a 菜单菜单 > 项目 > 应用版权...
  • 一个非常好的向导,有很多选项和一些开源许可证(Apache、EPL 等)的默认模板

I just tried it with eclipse 3.6 and it work fine.

我刚刚用 eclipse 3.6 试过它,它工作正常。

There is an update site to install it:

有一个更新站点可以安装它:

https://dl.bintray.com/jmini/Eclipse-Copyright-Generator/

回答by Bozho

Window > Preferences > Java > Code Style > Code Templates > Comments > Files

窗口 > 首选项 > Java > 代码样式 > 代码模板 > 注释 > 文件

回答by Andrew Eisenberg

In addition to the answer provided by Bozho, there are the releng tools provided by eclipse, which give you some menu item commands to fix copyrights in existing files. You can install the releng tools from this update site:

除了 Bozho 提供的答案之外,还有 eclipse 提供的 releng 工具,它为您提供一些菜单项命令来修复现有文件中的版权。您可以从此更新站点安装 releng 工具:

The Eclipse Project Updates - http://download.eclipse.org/eclipse/updates/4.3

Eclipse 项目更新 - http://download.eclipse.org/eclipse/updates/4.3

And there is a small bit information available on it here:

这里有一些关于它的信息:

https://wiki.eclipse.org/Development_Resources/How_to_Use_Eclipse_Copyright_Tool

https://wiki.eclipse.org/Development_Resources/How_to_Use_Eclipse_Copyright_Tool

回答by ilinca

In addition to Andrew Eisenberg's reply, here's what I found out about the Eclipse copyright tool. I found this to work best from all suggested solutions.

除了 Andrew Eisenberg 的回复,这里是我发现的关于Eclipse 版权工具的内容。我发现这在所有建议的解决方案中效果最好。

Pluses:

优点:

  • Easy to update copyright years or licence header.
  • Easy to apply to the whole project or just parts of it.
  • 易于更新版权年份或许可证标题。
  • 易于应用于整个项目或只是其中的一部分。

Minuses:

缺点:

  • Does not work on all types of files. At least didn't work on JSP files for me.
  • You can not set up multiple licenses and apply them as you wish. There's only one licence.
  • 不适用于所有类型的文件。至少对我来说对 JSP 文件不起作用。
  • 您无法设置多个许可证并根据需要应用它们。只有一张执照。

Customization (from preferences):

定制(从偏好):

Customization (from preferences)

定制(从偏好)

You can apply the license at the file or package level

您可以在文件或包级别应用许可证

You can apply the license at the file or package level

您可以在文件或包级别应用许可证

回答by JoseA

this is my setting under Window > Preferencers > Java > Code Style > Code Template > Code > New Java files:

这是我的设置Window > Preferencers > Java > Code Style > Code Template > Code > New Java files

/*
 * Copyright (c) 20XX XXXXXXXXX. All rights reserved. Whatever......
 */

${filecomment}  
${package_declaration}  

${typecomment}  
/**  
 *   
 * @author ${user}  
 *  
 */  
${type_declaration}  

回答by Arturo Volpe

The project that @Jmini link (Eclipse Copyright Generator) seems dead, you can use this plugin to add the headers: JAutoDoc, it's very easy to use and have a lot of utilities for javadoc.

@Jmini 链接(Eclipse Copyright Generator)的项目好像已经死了,你可以用这个插件来添加头文件:JAutoDoc,它很容易使用并且有很多javadoc 的实用程序。

You need to specify a licence in project|general > Preferences > java > JAutodoc > FileHeaderand later in the project use: project > JAutodoc > Add Header, make sure the option Replace Existing Headeris on.

您需要project|general > Preferences > java > JAutodoc > FileHeader在项目 use:中和以后指定许可证project > JAutodoc > Add Header,确保该选项Replace Existing Header处于打开状态。

The template is writing using Velocity, so you can add all the information you need as variables.

该模板使用Velocity编写,因此您可以将所需的所有信息添加为变量。