gpt4 book ai didi

java - 无法运行 Oracle 提供的 Doclet 类

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:45:14 26 4
gpt4 key购买 nike

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

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 中发现的其他一些东西,但同样,没有任何效果。 我错过了什么?给定的示例不应该工作吗?

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

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

使用那个选项,它应该可以正常工作(前提是你编译了 Example 类并且它确实位于作为参数传递给这个选项的目录中)。

关于java - 无法运行 Oracle 提供的 Doclet 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55336696/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com