Friday, September 30, 2011

How To Change @Author In Eclipse Templates

I have the problem of working with one project on multiple computers with different system user names.
This ends up in inconsisten javadoc comments where the tag @author get mixed up with all the system user names.

There are two solutions.

1. Change the system user name localy for the virtual machine Eclipse is running on.
This is the quick and dirty method, but it works globally.

Open your eclipse.ini file and add the following line after -vmargs: = your name

The dirty part is that it overrides the property which is used by some plugins that need to know the system user name you logged into the underlying OS. This could break them.

2. Change the templates in Eclipse
This hardcodes your user name into all the templates you want to change your name. But the templates are ex-, and importable. Define it once use it everywhere.
I know 2 templates with @author so far.

2.1 New Type Comment Template
Window -> Preferences -> Java -> Code Style -> Code Templates -> Comments -> Types
Press 'Edit...'
Change  @author ${user}  to  @author your name
If the Dialog is closed you can check the check box 'automatically add comments for new methods and types'.

Here you have the option to configure project specific templates. There is a link in the upper right corner 'Configure Project Specific Settings'.

2.2 @author Template
Window -> Preferences -> Java -> Editor -> Templates
Select in the list the template with the name '@author' .
Press 'Edit...'
Change  @author ${user}  to  @author your name

No comments:

Post a Comment