33

I like to put my email address within @author tags and would like them to be clickable mailto: links in the generated Javadoc.

How should I go about doing this correctly?

/**
 * I currently do the following, but would like to have my name 
 * displayed as the link rather than the email itself.
 *
 * @author {@link "mailto:my_email@email.example.com"}
 */
public class Useless { }

/**
 * I've tried this, but get warnings about unexpexted text where my name is.
 *
 * @author {@link "mailto:my_email@email.example.com" "Benoit St-Pierre"}
 */
public class Useless { }
Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662
Ben S
  • 68,394
  • 30
  • 171
  • 212

1 Answers1

44

The {@link} is Javadoc-specific markup. Javadocs, though, are HTML - so you can simply use

/**
 * Embed HTML directly into the Javadoc.
 *
 * @author <a href="mailto:my_email@email.exmaple.com">Benoit St-Pierre</a>
 */
public class Useless { }

Whether that's a good idea or not is a different matter. :-)

Andrzej Doyle
  • 102,507
  • 33
  • 189
  • 228
  • 16
    I personally would use `@author My full name `. Although that probably needs escaping to avoid the e-mail part being thought of as HTML tag. I still find the close ties to HTML in Javadoc a very unfortunate decision :-( – Joey Oct 02 '09 at 14:29
  • 2
    Most of the code I write is for internal purposes, so it's useful for others to be able to easily email me. I wouldn't do this for code in the wild. – Ben S Oct 02 '09 at 14:29
  • 5
    +1 Also the Javadoc conventions recommends the use of in-line links economically. The {@link} is supposed to be used to point to the documentation for the specified package, class or member name of a referenced class, not to link to e-mails or URLs (for a URL you should use @see) – JuanZe Oct 02 '09 at 14:32
  • 1
    This doesn't work for me - I get 404. I set the browser to default (Chrome) and saw this: http://127.0.0.1:51862/help/nftopic/mailto:myname@example.com like eclipse automatically assumes it's a javadoc link... – Eugene Marin Oct 07 '13 at 13:29
  • 13
    @Joey Why don't you write `@author My full name {@literal }` – mat_boy May 15 '14 at 14:47