71

Can anybody show me how to generate Javadoc from command line?

My project contains the package com.test and I want to put the generated documentation in files located in a specific folder like this: C:/javadoc/test.

Sam
  • 73
  • 2
  • 10
Damir
  • 54,277
  • 94
  • 246
  • 365
  • I recommend taking a look at the following: http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#runningjavadoc – Dartoxian Jan 04 '11 at 10:04

8 Answers8

49

You can refer the javadoc 8 documentation

I think what you are looking at is something like this:

javadoc -d C:\javadoc\test com.test
Chef Pharaoh
  • 2,387
  • 3
  • 27
  • 38
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
  • It automatically appends extra '/' after package name for me, like if package is : `com.test` and inside there is Main class then, it should make output as `com/test/Main.html` but it will try to write to file `com/test//Main.html` , weird! – Harshiv Apr 13 '17 at 18:21
  • Yay, this worked on Linux too. `javadoc -d path/to/output/folder myClass.java` – Chef Pharaoh Jan 30 '19 at 15:17
29

Oracle provides some simple examples:

http://docs.oracle.com/javase/8/docs/technotes/tools/windows/javadoc.html#CHDJBGFC

Assuming you are in ~/ and the java source tree is in ./saxon_source/net and you want to recurse through the whole source tree net is both a directory and the top package name.

mkdir saxon_docs
javadoc -d saxon_docs -sourcepath saxon_source -subpackages net
Sahil Agarwal
  • 555
  • 3
  • 12
infogizmo
  • 431
  • 4
  • 6
23

Let's say you have the following directory structure where you want to generate javadocs on file1.java and file2.java (package com.test), with the javadocs being placed in C:\javadoc\test:

C:\
|
+--javadoc\
|  |
|  +--test\
|
+--projects\
   |
   +--com\
      |
      +--test\
         |
         +--file1.java
         +--file2.java

In the command terminal, navigate to the root of your package: C:\projects. If you just want to generate the standard javadocs on all the java files inside the project, run the following command (for multiple packages, separate the package names by spaces):

C:\projects> javadoc -d [path to javadoc destination directory] [package name]

C:\projects> javadoc -d C:\javadoc\test com.test

If you want to run javadocs from elsewhere, you'll need to specify the sourcepath. For example, if you were to run javadocs in in C:\, you would modify the command as such:

C:\> javadoc -d [path to javadoc destination directory] -sourcepath [path to package directory] [package name]

C:\> javadoc -d C:\javadoc\test -sourcepath C:\projects com.test

If you want to run javadocs on only selected .java files, then add the source filenames separated by spaces (you can use an asterisk (*) for a wildcard). Make sure to include the path to the files:

C:\> javadoc -d [path to javadoc destination directory] [source filenames]

C:\> javadoc -d C:\javadoc\test C:\projects\com\test\file1.java

More information/scenarios can be found here.

shimizu
  • 998
  • 14
  • 20
8

For example if I had an application source code structure that looked like this:

  • C:\b2b\com\steve\util\
  • C:\b2b\com\steve\app\
  • C:\b2b\com\steve\gui\

Then I would do:

javadoc -d "C:\docs" -sourcepath "C:\b2b" -subpackages com

And that should create javadocs for source code of the com package, and all subpackages (recursively), found inside the "C:\b2b" directory.

Rakesh Soni
  • 10,135
  • 5
  • 44
  • 51
7

its simple go to the folder where your all java code is saved say E:/javaFolder and then javadoc *.java

example

E:\javaFolder> javadoc *.java

kshitij
  • 71
  • 1
  • 1
4

The answers given were not totally complete if multiple sourcepath and subpackages have to be processed.

The following command line will process all the packages under com and LOR (lord of the rings) located into /home/rudy/IdeaProjects/demo/src/main/java and /home/rudy/IdeaProjects/demo/src/test/java/

Please note:

  • it is Linux and the paths and packages are separated by ':'
  • that I made usage of private and wanted all the classes and members to be documented

rudy@rudy-ThinkPad-T590:~$ javadoc -d /home/rudy/IdeaProjects/demo_doc
-sourcepath /home/rudy/IdeaProjects/demo/src/main/java/
:/home/rudy/IdeaProjects/demo/src/test/java/
-subpackages com:LOR 
-private

rudy@rudy-ThinkPad-T590:~/IdeaProjects/demo/src/main/java$ ls -R 
.: com LOR
./com: example
./com/example: demo
./com/example/demo: DemowApplication.java
./LOR: Race.java TolkienCharacter.java

rudy@rudy-ThinkPad-T590:~/IdeaProjects/demo/src/test/java$ ls -R 
.: com
./com: example
./com/example: demo
./com/example/demo: AssertJTest.java DemowApplicationTests.java
Rudy Vissers
  • 5,267
  • 4
  • 35
  • 37
1

Link to JavaDoc

I believe this will surely help you.

javadoc -d C:/javadoc/test com.mypackage
SK.
  • 4,174
  • 4
  • 30
  • 48
1
D:\>javadoc *.java

If you want to create dock file of lang package then path should be same where your lang package is currently. For example, I created a folder name javaapi and unzipped the src zip file, then used the command below.

C:\Users\Techsupport1\Desktop\javaapi\java\lang> javadoc *.java
Max von Hippel
  • 2,856
  • 3
  • 29
  • 46
Sachindra N. Pandey
  • 1,177
  • 17
  • 15