Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 982
John Avatar asked Apr 09 '10 00:04

John


People also ask

How do I set default comments in Eclipse?

Simply go to: Window - Preferences - Java - Code Style - Code Templates - Comments - Types - Edit... and change ${user} to whatever you want. Also go to: Window - Preferences - Java - Editor - Templates - @author - Edit... and change ${user} to whatever you want.

How do I add a comment to a header in Eclipse?

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.

What is .Eclipse file?

. project file is created whenever you create an Eclipse project. I guess, when you loaded your workspace, your components had some files or when you loaded your workspace you chose to create project for the root folder. This would have created a . project file which contains name of the Eclipse project.

How do I create an existing source in Eclipse?

Easiest Method: Put all source files into one directory named after your project. i.e. "ProjectName" You can keep this directory in your workspace or it can be somewhere else. Start a new project in eclipse and name it using that same project name.


2 Answers

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

like image 179
Gabriel Ščerbák Avatar answered Oct 20 '22 03:10

Gabriel Ščerbák


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)

like image 17
Jmini Avatar answered Oct 20 '22 04:10

Jmini