I had a customized java doclet, it will call newInstance() on some classes:
clazz.newInstance()
When I ran it in Eclipse as Junit, it works well.
But When I ran it in maven , it throws an exception: NoClassDefFoundError
I checked that class, it is not in my current project, it is inside a maven dependency (third party jar).
I knew I can set classpath in maven-javadoc-plugin. But my project has more than 50 third party jars. How can I set those jars easily?
This is my code in maven pom:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>
<doclet>my.company.common.doclet.MyDoclet</doclet>
<docletPath>${project.build.directory}/../../shared-java/target/classes;${project.build.directory}/classes</docletPath>
<sourcePath>${project.build.directory}/../../shared-java/src/java;${project.build.directory}/../src/java</sourcePath>
<encoding>UTF-8</encoding>
<show>public</show>
<subpackages>my.company.api</subpackages>
<useStandardDocletOptions>false</useStandardDocletOptions>
<docletArtifacts>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
</docletArtifacts>
</configuration>
<executions>
<execution>
<id>attach-javadoc</id>
<phase>post-integration-test</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
Thanks!
I found the maven-javadoc-plugin do pass the whole classpath to my doclet. But the doclet ClassLoader.getSystemClassLoader() didn't use that classpath.
So I have to manually add those classpath into the current classLoader.
In Eclipse, it will automatically set those classpath.