How can I add a default header to my source files automatically in Eclipse?

EclipseEclipse Plugin

Eclipse Problem Overview


I'm trying to figure out how I can have a comment header automatically added to all new source files in my eclipse java project. I've looked around but I haven't found a simple solution to automate this process. I gave JAutodoc a try, and even though it does allow me to specify a header I still had to tell the plugin manually to inject the header and it didn't seem very fond of my keyword-subsitution.

I'm by the way using the Maven2 plugin for Eclipse for most of my projects if that's any help.

Any tips?

Eclipse Solutions


Solution 1 - Eclipse

Comments generation is configured in:

Main Menu -> Window -> Preferences -> Java -> Code Style -> Code Templates -> Configure generated code and comments

You can change directly the New Java files template: Code -> New Java files -> Edit

As of Eclipse 3.6 version, it is already configured that for new Java files ${filecomment} is inserted, so it is probably better to edit it instead:

Comments -> Files -> Edit

Solution 2 - Eclipse

If you want to add your comment a the top of the file (to add a copyright header), give a try to Eclipse Copyright Generator. There is a wizard that ask you what you want to include. Therefore you can add every kind of comment header.

After installation you get a new menu: Project > Apply Copyright....

In the include files field enter *.java to reduce the set of files.

see also this answer


As indicated in the comments, there is an other tool provided by the Eclipse Fundation: Eclipse Copyright Tool (as part of their releng tools)

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
QuestionJohnView Question on Stackoverflow
Solution 1 - EclipseGabriel ŠčerbákView Answer on Stackoverflow
Solution 2 - EclipseJminiView Answer on Stackoverflow