我想试验Doclet (JDK 9),所以我尝试了在这个链接。中逐步给出的所有东西--我没有在Example类中添加任何自定义的东西。正如甲骨文所给的那样(我刚刚声明了imports)。
Oracle发出命令:
javadoc -doclet Example \
-overviewfile overview.html \
-sourcepath source-location \
source-location/Example.java现在,当我运行给定的javadoc命令时,会得到以下错误:
javadoc: error -找不到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"
我尝试了很少其他的东西,但同样,没有工作。,我错过了什么?给出的示例不起作用吗?
示例类(万一您看到了一些我没有看到的东西):
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;
}
}发布于 2019-03-25 11:34:56
运行javadoc --help会显示以下选项:
-docletpath <path>
Specify where to find doclet class files使用该选项,它应该可以正常工作(只要您编译了示例类,并且它确实位于作为参数传递给该选项的目录中)。
https://stackoverflow.com/questions/55336696
复制相似问题