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?
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.
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.
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 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.
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;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With