49

I'm using Eclipse Indigo for Java.

I used to write comments over the methods. In that whenever I use @author tag, it automatically takes the username of the system who is currently logged in.

My question is : How can I change this @author tag configuration in such a way that it takes the name I have specified.

I have gone through the following link:

How to change the value of ${user} variable used in Eclipse templates

But it suggests to change the value of classpath variable $user. I don't want to do that. I want to change comment template through configuration.

Community
  • 1
  • 1
RAS
  • 8,100
  • 16
  • 64
  • 86
  • A flexible solution using EGit can be found [here](http://stackoverflow.com/questions/246192/how-to-change-the-value-of-user-variable-used-in-eclipse-templates/41412349#41412349) – Frelling Jan 01 '17 at 00:18
  • @Frelling Thanks for your response but I am not using GIT. I don't know how do you connect my question to EGit. – RAS Jan 02 '17 at 11:43
  • Too bad that you aren’t using Git. Given your profile, I take it that you use some other form of version control. The "connect" is that the solution is an answer to your referenced question above. You stated that you didn’t want to change values via Java system properties (e.g. `-Duser.name=bob`). EGit users only require a small tweak to templates to specify an author’s name at the system-, user-, or project-level based on configuration, as you asked. Granted, it’s a Git config, not Eclipse; but these days, especially in collaborative environments, Git is almost always involved. – Frelling Jan 02 '17 at 20:03

4 Answers4

65

There are several ways of accomplishing this. Open up Eclipse Preferences, type in Templates as your Filter, then select Java->Code Style->Code Templates. In the Code Templates widget, expand the Comments widget:

Eclipse Preferences - Java Code Templates

Looking through the expanded selection, you can see that there are templates defined for Types and Methods, amongst others. Select whichever template you want to edit, then click 'Edit'. You can now change the template as you see fit, for example by adding @author ${user} or whatever else to it:

Eclipse Preferences - Java Code Templates - Methods

Click 'Ok' out of all the dialogs to complete and save.

Perception
  • 79,279
  • 19
  • 185
  • 195
27

In the eclipse directory there is a file named: "eclipse.ini" open the file and add following line:

-Duser.name=desired name

after the "-vmargs" line

bdogru
  • 812
  • 1
  • 11
  • 19
  • Hey thanks for the reply but as I've already mentioned in the question, I don't want to change value of `$user` config. The same answer is also provided by someone in the question that I've posted as I've referred to. But anyways thanks for the help. – RAS Feb 02 '16 at 09:01
  • Sorry @RAS , I guess I missed that. – bdogru Feb 02 '16 at 09:04
  • Even though, that's the answer I was looking for. Thanks! – Hugo Baés Sep 26 '18 at 19:06
12

Project->Properties->Java Code Style->Code Template->

There is link Configure workspace setting

Select Comment->Types

Edit your name or whatever you want. enter image description here

Smit
  • 4,685
  • 1
  • 24
  • 28
  • 1
    Types refer to class level comments. I have already changed it. I want the same thing for methods. – RAS Dec 20 '12 at 08:17
  • 2
    @RAS - You can change the template for methods in the very same dialog as the one for types. Its the options about 3 items down from Types, and allows you to customize the templates for method Javadoc. Just add in `@author ${user}` or whatever else you want in there. – Perception Dec 20 '12 at 08:26
  • 1
    @Perception Thank you. RAS really made me confused by showing that link. – Smit Dec 20 '12 at 08:33
  • 1
    @Perception, This is the solution I was looking for. Please post it as a separate answer. – RAS Dec 20 '12 at 08:38
1

You can go to the Windows/Preference. Type int "Template" in the search box and go to Java/Code Style/Code Templates. The area you are searching is in the "Comments" part.

Hoàng Long
  • 10,746
  • 20
  • 75
  • 124
  • 1
    I have visited that portion but unable to find @author configuration. – RAS Dec 20 '12 at 08:11
  • As I understand, you are trying to change the comment which is auto-generated on each method. If that's the case, you can simply ignore/remove the @author, and input your own name in that. – Hoàng Long Dec 20 '12 at 08:16
  • 2
    That is what I'm doing write now. But I'm commenting multiple methods simultaneously. Manually writing is something I want to avoid. That's why I want to fix it at one place. – RAS Dec 20 '12 at 08:19
  • Yes, you can change it in the "Comment" pages. Just unfold them and you will see – Hoàng Long Dec 20 '12 at 08:28