Adding a standard comment header to all source files in eclipse

Eclipse

Eclipse Problem Overview


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.

Eclipse Solutions


Solution 1 - Eclipse

If you are looking for a tool with a good Eclipse integration (and a nice GUI), I suggest: 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, ...)

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

There is an update site to install it:

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

Solution 2 - Eclipse

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

Solution 3 - Eclipse

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:

The Eclipse Project Updates - 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

Solution 4 - Eclipse

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.

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.

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

Solution 5 - Eclipse

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.

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

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

Solution 6 - Eclipse

this is my setting under 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}  

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjaxView Question on Stackoverflow
Solution 1 - EclipseJminiView Answer on Stackoverflow
Solution 2 - EclipseBozhoView Answer on Stackoverflow
Solution 3 - EclipseAndrew EisenbergView Answer on Stackoverflow
Solution 4 - EclipseilincaView Answer on Stackoverflow
Solution 5 - EclipseArturo VolpeView Answer on Stackoverflow
Solution 6 - EclipseJoseAView Answer on Stackoverflow