211

In the Java APIs I can see Javadoc comments for packages.

How/where do I place Javadoc comments to document a package?

3 Answers 3

289

As of 1.5 you can define a package-info.java file and provide a standard javadoc style comment for a package:

com/foo/package-info.java:

/**
 * com.foo is a group of bar utils for operating on foo things.
 */
package com.foo;

//rest of the file is empty

Language specification for packages

3
  • 4
    Direct link to spec: docs.oracle.com/javase/specs/jls/se7/html/jls-7.html#jls-7.4.1
    – gavenkoa
    Commented Oct 5, 2012 at 11:57
  • 10
    in intellij you can right click on a package and the option to create this should be under the new file menu
    – bsautner
    Commented Apr 30, 2014 at 17:45
  • I found the file needed to be in packagename/src/packagename (with the rest of the source files)
    – trindflo
    Commented Apr 24, 2019 at 19:07
56

Up to and including Java 1.4, you had to provide a HTML file package.html, as described in the other answers.

Since Java 1.5 you can also provide a package-info.java, which contains a regular Javadoc comment (no HTML). The latter is preferred, as it gives you some extra features (notably package annotations).

Details: Sun's docs for javadoc

2
  • 2
    +1 for mentioning both ways, and the essential difference between them. By the way, at least IntelliJ IDEA currently has better support for package.html (Ctrl-Q on a package name shows the package Javadocs).
    – Jonik
    Commented Mar 23, 2009 at 19:29
  • 3
    Update to my previous comment: nowadays IDEA supports package-info.java just fine.
    – Jonik
    Commented May 28, 2013 at 19:38
3

With a package.html file at the package level (i.e. in the directory for that package). This should be a fully-formed HTML file, with the <html> tag defined in it

3
  • 2
    More details? What should the file look like?
    – jjnguy
    Commented Mar 8, 2009 at 22:23
  • 1
    It's an HTML file containing the description of your package. That's it! Commented Mar 8, 2009 at 22:25
  • 7
    This is the old way to do it. From Java 1.5 onwards you can use package-info.java
    – k2col
    Commented Nov 1, 2013 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.