Fixing scaladoc error “Cannot load the doclet class”

When running scaladoc with a custom generator, you can get the following error message:

error: Cannot load the doclet class com.garysieling.MicroformatScalaDoc 
(specified with -doc-generator): java.lang.ClassNotFoundException: 
com/garysieling/MicroformatScalaDoc. 

Leaving the default settings will generate the html version of scaladoc.

Unfortunately there are seven or eight different classpath arguments to scaladoc, which makes it tricky to execute. The key argument is “-toolcp”.

If you’re writing a custom doclet, you need to depend on the build output of your project – with sbt this will be in the target/scala-2.11/classes:

export CLASSPATH=./target/scala-2.11/classes

echo $CLASSPATH

scaladoc -verbose \
         -doc-generator com.garysieling.CustomScalaDoc \ 
         -toolcp $CLASSPATH \
         src/main/scala/com/garysieling/microformat.scala

Leave a Reply

Your email address will not be published. Required fields are marked *