I want to experiment with Doclets (JDK 9), so I tried everything step by step given in this link. I have not add anything custom in Example
class. It is exactly as Oracle gives it (I just declared the import
s).
Oracle gives the command:
javadoc -doclet Example \
-overviewfile overview.html \
-sourcepath source-location \
source-location/Example.java
Now when I run the given javadoc command, i get the following error:
javadoc: error - Cannot find doclet class Example
I tried some variations of the command since it seems to be a problem with directors but all of my tries have failed.
I place Example.java
in my Desktop folder: C:\Users\George\Desktop\
So, in my command line I cd C:\Users\George\Desktop\
. Then javac Example.java
(in case it wants it compiled).
And then, i try all the following commands, getting the same error.
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"
(+without quotes)
javadoc -doclet Example -overviewfile overview.html"C:\Users\George\Desktop\Example.java"
I tried few other things found in SO, but again, nothing works. What am i missing? Should not the given example work?
Example class (in case you see something i do not):
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;
}
}