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.

1

6 Answers 6

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/
12
  • 1
    Just bumped into this answer: awesome tool. Thank you!
    – Mena
    Jul 10, 2013 at 18:05
  • 5
    w91dev seems to be offline :(
    – rec
    Jun 24, 2014 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, 2014 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, 2014 at 16:36
  • 2
    New version published on GitHub/Bintray: jmini.github.io/Eclipse-Copyright-Generator
    – Jmini
    Apr 1, 2017 at 12:07
29

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

2
  • 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 6, 2013 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, 2013 at 8: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

3
  • Links worked fine for me, I guess they were updated.
    – ilinca
    Jun 2, 2015 at 9:08
  • Am using 3.8.1, but the update for this version probably did not exist. Hence tried with lower version 3.7 update. 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, 2016 at 5:16
  • This works for java but not for scala. Any options for scala files? Feb 1, 2017 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

2
  • This tool is no longer available for install Nov 13, 2021 at 10:48
  • @SergeyKarpushin You'll have to configure it from an older update site. I installed mine from the 4.19 Eclipse Update Site and it works fine.
    – Nzall
    Mar 7, 2022 at 15:59
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.

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}  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.