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:
- Java Doc by Eclipse
- Java Doc from Commandline
Now we will continue with the same previous comments file example to generate java documents by both ways:
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
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 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:
C:/Users/username/CalculatorTest.html
javadoc you_java_file_path
You can use javadoc command as below.
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:
Syntax:
C:\myprojects> javadoc -d [path to javadoc destination directory] [package name]
Example:
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.
Syntax:
C:\> javadoc -d [path to javadoc destination directory] -sourcepath [path to package directory] [package name]
Example:
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).
Syntax:
C:\> javadoc -d [path to javadoc destination directory]
Example:
C:\> javadoc -d C:\javadoc\test C:\projects\com\test\file1.java
If you need to generate Javadoc from the same folder use wildcard(*) and mentioned in the given example.
Example:
E:\MyJavaFileFolder> javadoc *.java
References
https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javadoc.html
You must log in to post a comment.