Java: How to generate Java doc by command line and Eclipse IDE?

In the previous post, you learn about the type of comments supported by Java. Now in this post will explain the ways to generate Java documentation of project by both ways:

  1. Java Doc by Eclipse
  2. Java Doc from Commandline

Now we will continue with the same previous comments file example to generate java documents by both ways:

Java Comments Type

Java Doc generation from Eclipse

Follow the below steps to generate Java API documentation:

  • Go to Project tab
  • Select the option “Generate Javadoc”
  • Follow steps in the screen as below:
  • Click on Next button
  • Click on Next button again
  • Finally, click on Finish button

java Doc generation in eclipse 1.jpg

In your console logs will see a link like as below to java doc of file.

D:\Saurabh Gupta\Workspace-learning\JavaExamples\doc\com\common\statements\CalculatorTest.html

Open this file you will see java doc comments on class and method level of this file as highlighted:

Java doc generation eclipse 2

Java Doc generation from Command-line

To generate Java doc from command-line you can use the below command.  It will generate Java doc file in your user directory (default) on below location:


javadoc you_java_file_path

You can use javadoc command as below.

Java doc generation from commnad line

Here are some of the scenarios to generate java doc:

Java doc on a specific location from the package

You can use below command to generate Javadoc for all files with the package from the projects folder:


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


C:\myprojects> javadoc -d C:\javadoc\test com.fiot.test

Java doc generation execution from some other location

You can use the below command when you need to generate java docs and want to run the script from a different location.


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


C:\> javadoc -d C:\javadoc\test -sourcepath C:\myprojects com.fiot.test

Java doc generation for selected files

You can use the below command when you need to generate Javadoc for specific files then you can mentioned files path separated by spaces (or use an asterisk(*) for a wild card).


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


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

If you need to generate Javadoc from the same folder use wildcard(*) and mentioned in the given example.


E:\MyJavaFileFolder> javadoc *.java