71

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?

John
  • 2,571
  • 6
  • 32
  • 40

2 Answers2

107

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

Gabriel Ščerbák
  • 18,240
  • 8
  • 37
  • 52
  • Thanks, that seems to do the trick. I'll take a closer look at, I should be able to figure it out now that I've got directions. – John Apr 09 '10 at 01:03
  • 12
    I had to also check the `Automatically add comments for new methods and types` option to make it work. – jeremija Jun 16 '14 at 10:17
  • As jeremija said, this answer should be edited to include that "Automatically add comments for new methods and types" – CarlosGoncalves Apr 19 '18 at 09:54
17

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)

Jmini
  • 9,189
  • 2
  • 55
  • 77
  • 4
    Eclipse Copyright Generator works for existing files. The accepted answer works for newly created files. – ytw Oct 17 '12 at 23:46
  • Eclipse Copyright Generator seems to not work with php files. – Rmannn Nov 23 '12 at 14:09
  • I have publised a new version on Github/Bintray: https://jmini.github.io/Eclipse-Copyright-Generator/ – Jmini Apr 01 '17 at 12:08
  • The new name is "releng tools". https://wiki.eclipse.org/Development_Resources/How_to_Use_Eclipse_Copyright_Tool – olidem Mar 06 '18 at 07:37