Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I add JavaDoc to a package easily with Eclipse?

I use javadoc to document my classes and methods. I would like to add some overview information to my packages, too. I like how Eclipse creates a stub of a matching Doc Comment for each class or method once I type /**<Enter>. Does Eclipse have an easy way to generate a package.html file, too?

like image 305
Hanno Fietz Avatar asked May 21 '09 15:05

Hanno Fietz


People also ask

Where do I put javadoc in Eclipse?

Step 1 − Open eclipse, select the option Project →Generate Javadoc. Step 2 − Select the javadoc.exe file from the bin folder of java installation directory, select the destination folder for the generated java doc and select Next. finish button.

How do I write javadoc comments in Eclipse?

Shift-Alt-J is a useful keyboard shortcut in Eclipse for creating Javadoc comment templates.

How do you add a javadoc?

Add a Javadoc using context actionsPlace the caret at the declaration in the editor, press Alt+Enter , and select Add Javadoc from the list.

What is the javadoc Command in Eclipse?

The javadoc command parses the declarations and documentation comments in a set of Java source files and produces a corresponding set of HTML pages that describe (by default) the public and protected classes, nested classes (but not anonymous inner classes), interfaces, constructors, methods, and fields.


2 Answers

Update 4 years later (Oct. 2013)

javabeangrinder's answer (upvoted) mentions the following trick:

To create a package-info.java file in an existing package:

  • Right click on the package where you want a package-info.java.
  • Select new->package.
  • Check the Create package.info.java check box.
  • Click on Finish

Original answer (May 2009)

There is no template or wizard to easily create a package.html file.

As mmyers said in his comment, since Java1.5, the correct file to create would be package-info.java.
That file can be used not only for javadocs, but also for package-level annotations (as illustrated here).

There is an opened Bug (#86168) for demanding a wizard for the creation of package-info.java (since the class wizard does not allow the package-info name).

The reflections on that topic are on since... 2005! The problem is that any solution should be implemented in a way that it also helps with 1.4 code.

The current workaround is to create a package-info.java as a text file.
From that point forward, package-info.java behaves as a normal Java class, and Eclipse places a package-info.class file in the output folder.
The Javadocs are correctly built using package-info.java, and not the package.html file.

alt text
(source: developpez.com)


Note (in response to Strawberry's comment):

  • bug 77451 (2004!, for package.html)
  • bug 163633 and bug 163926 (2006, for package-info.java)

both wish a preview of the package overview in package-info.java in the Javadoc view.

So far, no patch has been proposed/implemented.
There is simply not enough demands for that feature to be added.

like image 125
VonC Avatar answered Nov 09 '22 01:11

VonC


In eclipse

Since package-info.java isn't a valid identifier for a class it cannot be created as a class in Eclipse.

I found that when you create a new package there is a check box to check if you want a package-info.java.

To create a package-info.java file in an existing package:

  1. Right click on the package where you want a package-info.java.
  2. Select new->package.
  3. Check the Create package.info.java check box.
  4. Click on Finish
like image 21
javabeangrinder Avatar answered Nov 08 '22 23:11

javabeangrinder