无法 运行 Oracle 提供的 Doclet class

Cannot run Doclet class given by Oracle

我想尝试使用 Doclets (JDK 9),所以我一步一步地尝试了这个link.中给出的所有内容我没有添加任何东西Example class 中的自定义。它与 Oracle 提供的完全一样(我刚刚声明了 imports)。

Oracle给出命令:

javadoc -doclet Example \
       -overviewfile overview.html \
       -sourcepath source-location \
       source-location/Example.java

现在,当我 运行 给定的 javadoc 命令时,出现以下错误:

javadoc: error - Cannot find doclet class Example

我尝试了命令的一些变体,因为这似乎是导演的问题,但我的所有尝试都失败了。

我将 Example.java 放在我的桌面文件夹中:C:\Users\George\Desktop\

因此,在我的命令行中 cd C:\Users\George\Desktop\。然后javac Example.java(以防它想要编译)。

然后,我尝试了以下所有命令,得到了同样的错误。

javadoc -doclet Example -overviewfile overview.html -sourcepath ./ ./Example.java

.

javadoc -doclet Example -overviewfile overview.html -sourcepath "C:\Users\George\Desktop\" "C:\Users\George\Desktop\Example.java"

(+不带引号)

javadoc -doclet Example -overviewfile overview.html"C:\Users\George\Desktop\Example.java"

我尝试了在 SO 中发现的其他一些东西,但同样,没有任何效果。 我错过了什么?给定的例子不应该工作吗?

示例class(以防你看到我没有看到的东西):

public class Example implements Doclet {
    Reporter reporter;
    String overviewFile;

    public static void main(String[] args) {
    }

    public Example() {
        // TODO Auto-generated constructor stub
    }

    @Override
    public void init(Locale locale, Reporter reporter) {
        reporter.print(Kind.NOTE, "Doclet using locale: " + locale);
        this.reporter = reporter;
    }

    public void printElement(DocTrees trees, Element e) {
        DocCommentTree docCommentTree = trees.getDocCommentTree(e);
        if (docCommentTree != null) {
            System.out.println("Element (" + e.getKind() + ": " + e + ") has the following comments:");
            System.out.println("Entire body: " + docCommentTree.getFullBody());
            System.out.println("Block tags: " + docCommentTree.getBlockTags());
        }
    }

    @Override
    public String getName() {
        return "Example";
    }

    @Override
    public Set<? extends Option> getSupportedOptions() {
        Option[] options = { new Option() {
            private final List<String> someOption = Arrays.asList("-overviewfile", "--overview-file", "-o");

            @Override
            public int getArgumentCount() {
                return 1;
            }

            @Override
            public String getDescription() {
                return "an option with aliases";
            }

            @Override
            public Option.Kind getKind() {
                return Option.Kind.STANDARD;
            }

            @Override
            public List<String> getNames() {
                return someOption;
            }

            @Override
            public String getParameters() {
                return "file";
            }

            @Override
            public boolean process(String opt, List<String> arguments) {
                overviewFile = arguments.get(0);
                return true;
            }
        } };
        return new HashSet<>(Arrays.asList(options));
    }

    @Override
    public SourceVersion getSupportedSourceVersion() {
        return SourceVersion.latest();
    }

    @Override
    public boolean run(DocletEnvironment docEnv) {
        reporter.print(Kind.NOTE, "overviewfile: " + overviewFile);
        // get the DocTrees utility class to access document comments
        DocTrees docTrees = docEnv.getDocTrees();

        // location of an element in the same directory as overview.html
        try {
            Element e = ElementFilter.typesIn(docEnv.getSpecifiedElements()).iterator().next();
            DocCommentTree docCommentTree = docTrees.getDocCommentTree(e, overviewFile);
            if (docCommentTree != null) {
                System.out.println("Overview html: " + docCommentTree.getFullBody());
            }
        } catch (IOException missing) {
            reporter.print(Kind.ERROR, "No overview.html found.");
        }

        for (TypeElement t : ElementFilter.typesIn(docEnv.getIncludedElements())) {
            System.out.println(t.getKind() + ":" + t);
            for (javax.lang.model.element.Element e : t.getEnclosedElements()) {
                printElement(docTrees, e);
            }
        }
        return true;
    }
}

运行 javadoc --help 显示以下选项:

-docletpath <path>
              Specify where to find doclet class files

使用该选项,它应该可以正常工作(前提是您编译了示例 class 并且它确实位于作为该选项的参数传递的目录中)。