How can I generate javadocs using Java?

I am writing a Java application that will allow me to compile a Java project based solely on its file structure so that I can write code and compile without an IDE. The problem I'm currently facing is that I would like to automatically generate javadoc at compile time, although while Java 6 supplies the JavaCompiler object for work, I cannot find a way to use the javadoc command.

How can I create javadoc html for my projects using java code?

+7
source share
5 answers

Just in case, when you did not know that Apache Ant and Apache Maven are tools that exist to achieve a similar goal with respect to what you write (compilation without an IDE).

Both of them are built in to support javadoc generation. The syntax for Ant is as follows:

<!-- publish javadoc --> <target name="javadoc" description="Creates javadoc for IMP."> <delete dir="${web-javadoc}"/> <javadoc sourcepath="${source}" defaultexcludes="no" destdir="${web-javadoc}" author="true" version="true" use="true" windowtitle="IMP: Integrated Mechanisms Program" overview="${source}/overview.html" classpathref="debug.classpath" stylesheetfile="${javadoc-theme}/stylesheet.css" /> <copy file="${javadoc-theme}/javadoc.jpg" tofile="${web-javadoc}/javadoc.jpg"/> </target> 

If you really want to create it yourself, you want to use the Doclet API

 import com.sun.javadoc.*; public class ListClass { public static boolean start(RootDoc root) { ClassDoc[] classes = root.classes(); for (int i = 0; i < classes.length; ++i) { System.out.println(classes[i]); } return true; } } 
+7
source

The Javadoc tool has a programming interface with public methods for invoking the Javadoc tool from another program written in Java. These methods are located in the com.sun.tools.javadoc.Main class in lib/tools.jar .

From: http://download.oracle.com/javase/6/docs/technotes/guides/javadoc/standard-doclet.html#runningprogrammatically

+5
source

Type javadoc in the terminal - it will give you a good list of options. The simplest:

 javadoc -d your_output_directory -classpath your_classpath -sourcepath your_sourcefile_dir 
+5
source
+1
source

There is a javadoc command, it comes with the JDK (man javadoc on unix platforms)

However, there are other ways. How do you compile the code? If you use an automatic build tool like ant or maven, you can add a javadoc task to automatically create javadocs whenever you compile your code

http://ant.apache.org/manual/Tasks/javadoc.html

for more information about ant (other tools have similar features, see the tool documentation for more information)

That's what I do, it works brilliantly.

0
source

All Articles