본문 바로가기

Java

Java API 문서 생성도구 javadoc 사용하기

내가 작성한 자바 프로그램 소스에 대한 API 문서를 만들어 보자.

JDK에서 기본으로 제공하는 javadoc을 사용하면 된다.


javadoc의 사용법은 다음과 같다.

usage: javadoc [options] [packagenames] [sourcefiles] [@files]
-overview <file>          Read overview documentation from HTML file
-public                   Show only public classes and members
-protected                Show protected/public classes and members (default)
-package                  Show package/protected/public classes and members
-private                  Show all classes and members
-help                     Display command line options and exit
-doclet <class>           Generate output via alternate doclet
-docletpath <path>        Specify where to find doclet class files
-sourcepath <pathlist>    Specify where to find source files
-classpath <pathlist>     Specify where to find user class files
-exclude <pkglist>        Specify a list of packages to exclude
-subpackages <subpkglist> Specify subpackages to recursively load
-breakiterator            Compute 1st sentence with BreakIterator
-bootclasspath <pathlist> Override location of class files loaded
                          by the bootstrap class loader
-source <release>         Provide source compatibility with specified release
-extdirs <dirlist>        Override location of installed extensions
-verbose                  Output messages about what Javadoc is doing
-locale <name>            Locale to be used, e.g. en_US or en_US_WIN
-encoding <name>          Source file encoding name
-quiet                    Do not display status messages
-J<flag>                  Pass <flag> directly to the runtime system
-X                        Print a synopsis of nonstandard options

Provided by Standard doclet:
-d <directory>                    Destination directory for output files
-use                              Create class and package usage pages
-version                          Include @version paragraphs
-author                           Include @author paragraphs
-docfilessubdirs                  Recursively copy doc-file subdirectories
-splitindex                       Split index into one file per letter
-windowtitle <text>               Browser window title for the documenation
-doctitle <html-code>             Include title for the overview page
-header <html-code>               Include header text for each page
-footer <html-code>               Include footer text for each page
-top    <html-code>               Include top text for each page
-bottom <html-code>               Include bottom text for each page
-link <url>                       Create links to javadoc output at <url>
-linkoffline <url> <url2>         Link to docs at <url> using package list at <url2>
-excludedocfilessubdir <name1>:.. Exclude any doc-files subdirectories with given name.
-group <name> <p1>:<p2>..         Group specified packages together in overview page
-nocomment                        Supress description and tags, generate only declarations.
-nodeprecated                     Do not include @deprecated information
-noqualifier <name1>:<name2>:...  Exclude the list of qualifiers from the output.
-nosince                          Do not include @since information
-notimestamp                      Do not include hidden time stamp
-nodeprecatedlist                 Do not generate deprecated list
-notree                           Do not generate class hierarchy
-noindex                          Do not generate index
-nohelp                           Do not generate help link
-nonavbar                         Do not generate navigation bar
-serialwarn                       Generate warning about @serial tag
-tag <name>:<locations>:<header>  Specify single argument custom tags
-taglet                           The fully qualified name of Taglet to register
-tagletpath                       The path to Taglets
-Xdocrootparent <url>             Replaces all appearances of @docRoot followed by /.. in doc comments with <url>
-charset <charset>                Charset for cross-platform viewing of generated documentation.
-helpfile <file>                  Include file that help link links to
-linksource                       Generate source in HTML
-sourcetab <tab length>           Specify the number of spaces each tab takes up in the source
-keywords                         Include HTML meta tags with package, class and member info
-stylesheetfile <path>            File to change style of the generated documentation
-docencoding <name>               Output encoding name

 

[doc] 폴더에 javadoc으로 생성되는 API Document를 생성해보자.

사용법 : javadoc -d <문서가 생성될 위치> <문서화할 소스 파일 위치>

javadoc -d doc ./src/*.java




다음과 같이 [doc] 폴더에 API 문서 파일이 생성되었다.



파일을 열면 다음과 같이 깔끔한 API 문서가 보인다.