I'm trying to get javadocs for my classes directly from console with following code javadoc -sourcepath ./src/main java.packageName
. Those classes have dependencies on external libraries (e.g junit.framework
). This code is easy to compile from IntelliJ IDEA or via mvn clean install
, but when I'm trying to create javadocs I face the problem that external classes and packages cannot be recognized (e.g. error: package junit.framework does not exist
). Same problem occurs with JDK 8 as well, but there those are warnings and javadocs are generated anyway.
-
1Why not use Maven to generate the Javadoc? https://maven.apache.org/plugins/maven-javadoc-plugin/ – Slaw Dec 23 '20 at 21:19
-
maven javadoc plugin usage is here if you decide to go that route instead (as @Slaw suggests): https://maven.apache.org/plugins/maven-javadoc-plugin/usage.html – Woodchuck Dec 23 '20 at 21:37
2 Answers
There are two approaches you could take to get the javadocs to build from the command line:
Add the maven-javadoc-plugin to your project's POM file so that you can use (for example)
mvn javadoc:javadoc
to generate the javadocs. See the plugin documentation for more details.Run
javadoc
directly with the correct command-line arguments.
I suspect that there are a couple of reasons why your current attempt is failing:
You appear to be generating javadocs for your
src/test
tree. That may be unintentional.(If the above "error: ..." is coming from the
src/main
javadoc generation, I'm puzzled why yoursrc/main
source code is referring to thejunit.framework
package. It could do, but production code wouldn't normally depend on a test framework.)You need to use a
-classpath
option to telljavadoc
where to find the external libraries are.

- 698,415
- 94
- 811
- 1,216
-
That was about `-classpath`. It seems we need to manually pass all class paths – Eugen Dec 24 '20 at 12:16
"This code is easy to compile from intellij" just use the JavaDoc function from intellij. It should work
Tools - Generate JavaDoc

- 77
- 11
-
Well it works, but I need to know how to do it directly from console. It will be run from sh scripts – Eugen Dec 23 '20 at 21:28
-