如何通过reflection阅读Javadoc注释?

我需要知道如何在运行时读取Javadoc注释(可能是通过reflection?)

说我有以下function:

/** * function that do some thing */ public void myFunc() { //... } 

在运行时,我可以通过reflection获得有关此函数的大量信息。但是无法读取注释。 所以问题是,如何在运行时阅读这个javadoc注释。

考虑使用注释而不是Javadoc并编写注释处理器。

Doclet课程:

 public class ExtractCommentsDoclet { public static boolean start(RootDoc root) throws IOException { for (ClassDoc c : root.classes()) { print(c.qualifiedName(), c.commentText()); for (FieldDoc f : c.fields(false)) { print(f.qualifiedName(), f.commentText()); } for (MethodDoc m : c.methods(false)) { print(m.qualifiedName(), m.commentText()); if (m.commentText() != null && m.commentText().length() > 0) { for (ParamTag p : m.paramTags()) print(m.qualifiedName() + "@" + p.parameterName(), p.parameterComment()); for (Tag t : m.tags("return")) { if (t.text() != null && t.text().length() > 0) print(m.qualifiedName() + "@return", t.text()); } } } } return true; } private static void print(String name, String comment) throws IOException { if (comment != null && comment.length() > 0) { new FileWriter(name + ".txt").append(comment).close(); } } } 

和maven执行:

  maven-javadoc-plugin true   compile  aggregate     ExtractCommentsDoclet ${project.build.directory}/classes ${project.build.outputDirectory}/META-INF false   

从类路径中读取文档:META-INF / apidocs

你不能。 它们已从编译的代码中删除。

你不能这样做,因为javadoc没有被编译成最终的类。