无法运行Oracle提供的Doclet类

问题描述 投票:2回答:1

我想试验Doclets(JDK 9),所以我在这个link.中逐步尝试了所有内容我没有在Example类中添加任何自定义。正如Oracle给出的那样(我只是添加了导入)。

Oracle给出了命令:

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

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

javadoc:错误 - 找不到doclet类示例

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

我将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中尝试了很少的其他东西,但是再一次,没有任何作用。我错过了什么?这个例子不应该起作用吗?

示例类(如果你看到我不知道的话):

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;
    }
}
java javadoc java-9 doclet
1个回答
1
投票

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

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

使用该选项,它应该工作正常(假设您编译了Example类,它确实位于作为此选项的参数传递的目录中)。

© www.soinside.com 2019 - 2024. All rights reserved.