Adding a standard comment header to all source files in eclipse
Asked Answered
Q

6

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.

Quebec answered 5/11, 2010 at 12:3 Comment(1)
possible duplicate of How to manage license banners in source files of Eclipse plug-in projectsLemcke
M
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/
Muzhik answered 30/3, 2011 at 20:26 Comment(12)
Just bumped into this answer: awesome tool. Thank you!Brill
It works pretty well but with one annoying caveat on Windows: It disregards the current line endings and converts files to CRLF.Stilted
w91dev seems to be offline :(Earthly
@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.Muzhik
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.Earthly
@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.Muzhik
I think the website is down or the project is gone ?Lozengy
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.Muzhik
Instructions to build from the source as well as a compiled binary are available hereFredi
New version published on GitHub/Bintray: jmini.github.io/Eclipse-Copyright-GeneratorMuzhik
How to include other file types for exampe .jsx and .json etc?Fingerboard
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: @MuzhikCallihan
D
29

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

Dunois answered 5/11, 2010 at 12:6 Comment(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 codeBigot
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.Gamy
A
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

Amphigory answered 5/11, 2010 at 19:32 Comment(3)
Links worked fine for me, I guess they were updated.Couchant
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.Gahan
This works for java but not for scala. Any options for scala files?Tarnetgaronne
C
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

Couchant answered 2/6, 2015 at 9:6 Comment(2)
This tool is no longer available for installCallihan
@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.Markmarkdown
I
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.

Inveigle answered 5/6, 2014 at 14:21 Comment(0)
J
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}  
Jessy answered 28/11, 2017 at 17:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.