如何使用Java生成javadocs

如何使用Java生成javadocs

本文介绍了如何使用Java生成javadocs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个Java应用程序,它将允许我仅基于文件结构来编译Java项目 ,这样我就可以编写代码并在没有IDE的情况下进行编译.我目前遇到的问题是,我想在编译时自动生成javadoc,尽管Java 6提供了可使用的JavaCompiler对象,但我找不到使用javadoc命令的方法. /p>

如何使用Java代码为我的项目生成javadoc html?

解决方案

以防万一您同时不了解 Apache Ant Apache Maven 是为实现与您正在编写的内容(无需IDE进行编译)相似的目标而存在的工具.

它们两者都内置了对生成javadoc的支持. Ant语法如下:

<!-- 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>

如果您真的想自己生成它,则可以使用

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;
    }
}

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?

解决方案

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;
    }
}

这篇关于如何使用Java生成javadocs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 05:47