58

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.

jax
  • 37,735
  • 57
  • 182
  • 278
  • 1
    possible duplicate of [How to manage license banners in source files of Eclipse plug-in projects](http://stackoverflow.com/questions/204676/how-to-manage-license-banners-in-source-files-of-eclipse-plug-in-projects) – Narkha Oct 30 '14 at 12:31

6 Answers6

53

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/
Jmini
  • 9,189
  • 2
  • 55
  • 77
  • 1
    Just bumped into this answer: awesome tool. Thank you! – Mena Jul 10 '13 at 18:05
  • It works pretty well but with one annoying caveat on Windows: It disregards the current line endings and converts files to CRLF. – Trevor Robinson May 06 '14 at 04:18
  • 5
    w91dev seems to be offline :( – rec Jun 24 '14 at 10:32
  • 1
    @rec: Source seems still available on sourceforge. Lets hope someone will looks into it, compile the project and publish it to an update site somewhere else. This is one of the problem with open-source software. – Jmini Jun 27 '14 at 13:13
  • 1
    Imagine it wasn't open-source - then it would be gone for good. Like this, at least somebody could re-post it or even take over the project on sourceforge. – rec Jun 27 '14 at 16:36
  • @rec: Absolutly agree with you... I wrote "Problem", I meant "Property" of oss. This would has been more neutral. I am user of open-source software and also a contributor. – Jmini Jun 30 '14 at 09:42
  • I think the website is down or the project is gone ? – Mohamed ALOUANE Dec 06 '14 at 12:38
  • The project and the source are still available (see the discussion we had with "rec" in the previous comment). Maybe someone will step up and continue to maintain the project. – Jmini Dec 08 '14 at 07:57
  • Instructions to build from the source as well as a compiled binary are available [here](https://www.eclipse.org/forums/index.php/t/796282/) – hendalst Nov 30 '15 at 07:04
  • 2
    New version published on GitHub/Bintray: https://jmini.github.io/Eclipse-Copyright-Generator/ – Jmini Apr 01 '17 at 12:07
  • How to include other file types for exampe .jsx and .json etc? – UI_Brain Sep 09 '21 at 13:37
  • This should no longer be marked as an answer because plugin can no longer be installed via market place as bintray removed support for the hosting. FYI: @Jmini – Sergey Karpushin Nov 13 '21 at 10:39
29

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

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • 2
    Similar to this `Window > Preferences > Java > Code Style > Code Templates > Code > New Java Files` can be used to set a standard comment header for new Java code – RobV Feb 06 '13 at 17:16
  • 5
    In addition, make sure the checkbox 'Automatically add comments for new methode' is enabled in the lower part of the Java - Code Style - Code Templates section. – dschulten Dec 19 '13 at 08:58
9

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

Trevor Robinson
  • 15,694
  • 5
  • 73
  • 72
Andrew Eisenberg
  • 28,387
  • 9
  • 92
  • 148
  • Links worked fine for me, I guess they were updated. – ilinca Jun 02 '15 at 09:08
  • Am using 3.8.1, but the update for this version probably did not exist. Hence tried with lower version 3.7 update. http://download.eclipse.org/eclipse/updates/3.7 did work for me of installation. @Andrew: any reference for the list of "variables" supported in this copyright text, like ${date} was one. I need to know, some like ${file}, ${user}, date-in-dd/mm/yyyy format, etc. – parasrish Apr 13 '16 at 05:16
  • This works for java but not for scala. Any options for scala files? – Prabodh Mhalgi Feb 01 '17 at 10:29
7

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

ilinca
  • 1,343
  • 15
  • 17
4

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.

Arturo Volpe
  • 3,442
  • 3
  • 25
  • 40
3

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}  
Aniruddha Das
  • 20,520
  • 23
  • 96
  • 132
JoseA
  • 189
  • 1
  • 3
  • 8