Problems creating custom javadoc; 'can't find doclet'

I am going to create my own Javadoc generator using a Doclet , but I am having some problems.

I follow the official documentation and initially had problems including the tools.jar file in my project, but I managed to fix it.

My problem is that after executing this command ...

 javadoc -doclet ListClass -docletpath . MyClass.java 

... I get a message ...

javadoc: error - Cannot find doclet ListClass class

As I said, I basically followed the tutorials from the official documentation, but here is my code for reference.

ListClass.java

 import com.sun.javadoc.*; public class ListClass { public static boolean start(RootDoc root) { ClassDoc[] classes = root.classes(); for (int i = 0; i < classes.length; ++i) { System.out.println(classes[i]); } return true; } } 

And MyClass.java :

 /** * Documentation for my class */ public class MyClass { public static void main(String[] args) { } /** * Documentation for my static void method * * @param param This is the parameter it takes in */ public static void myStaticVoidMethod(String param) { } } 

So I ask why I get the error message that I wrote above. If someone could provide a more detailed guide on how Doclet works, that would be great too.


Note. I am using IntelliJ IDE for my project. Here is my directory structure:

  • .idea
    • ...
  • of
    • ...
  • CSI
    • ListClass.java
    • Myclass.java
  • JavadocGenerator.iml
+5
source share
1 answer

You need to compile the ListClass file. Sort of:

 javac -d . ListClass.java -cp /path/to/tools.jar 

Doclet classes are part of the jar toolkit, so you will need to include it in your compilation time dependency.

Then your team

 javadoc -doclet ListClass -docletpath . MyClass.java 

must work.

change

For your project structure, if you are compiling from the root directory, be sure to link to your files through your subdirectories and make sure that any absolute Windows paths are double:

 javac -d . ./src/ListClass.java -cp "C:/Program Files/Java/jdk1.8.0_66/lib/tools.jar" 

This will create a compiled ListClass file in the root of the project, and from there it will use your javadoc command:

 javadoc -doclet ListClass -docletpath . ./src/MyClass.java 

It would be better to create a class catalog to host the compiled classes, rather than at the root of the project, but I just work with the structure you provided. See the documentation for javac and javadoc for more information.

+1
source

Source: https://habr.com/ru/post/1247651/


All Articles