Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I generate javadocs using Java?

Tags:

java

javadoc

I'm writing a Java app that will let me compile a Java project based solely on it's file structure so that I can write code and compile without an IDE. The problem that I'm currently having is that I would like to automatically generate the javadoc while I'm compiling, though while Java 6 supplies a JavaCompiler object to work with, I can't find a way to use the javadoc command.

How can I generate the javadoc html for my projects using Java code?

like image 388
Kyle Sletten Avatar asked Aug 10 '11 00:08

Kyle Sletten


People also ask

How are javadocs created?

To create a JavaDoc you do not need to compile the java file. To create the Java documentation API, you need to write Javadoc followed by file name. After successful execution of the above command, a number of HTML files will be created, open the file named index to see all the information about classes.

Does javadoc come with Java?

Javadoc 1.4 is included in Java 2 SDK, Standard Edition v 1.4. Javadoc 1.3 is included in Java 2 SDK, Standard Edition v 1.3. Javadoc 1.2 is included in Java 2 SDK, Standard Edition v 1.2.

How can you generate javadoc documentation for your code?

Step 1 − Open eclipse, select the option Project →Generate Javadoc. Step 2 − Select the javadoc.exe file from the bin folder of java installation directory, select the destination folder for the generated java doc and select Next. finish button.

What is a javadoc in Java?

What Does Javadoc Mean? Javadoc is a documentation tool for the Java programming language. The document it creates from the Java sources is in HTML format and describes the application programming interface.


1 Answers

Just in case you weren't aware both Apache Ant and Apache Maven are tools that exist to accomplish a similar goal to what you are writing (compiling without an IDE).

Both of them have built in support for generating javadoc. Ant syntax looks like this:

<!-- 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 generate it on your own 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;
    }
}
like image 127
JohnKlehm Avatar answered Sep 26 '22 01:09

JohnKlehm