简体   繁体   中英

Add jar to doclet classpath using maven-javadoc-plugin

I wrote a doclet that collects some data and passes it to a reporter. I want this reporter to be exchangeable. I tried to add a reporter implementation to the doclet classpath using an additionalDependency and/or a pluginDependency. I can't load the reporter implementation with the Java 6 service loader and it also doesn't work to get the class using the doclets class loader or the threads context class loader.

How can I get the test.TestReporterImpl into the test-doclet classpath?

In the doclet:

apiReporterServiceLoader = ServiceLoader.load(TestReporter.class); // test.TestReporter

apiReporterServiceLoader.iterator().hasNext(); // false

Thread.currentThread().getContextClassLoader().loadClass("test.TestReporterImpl"); // ClassNotFoundException

getClass().getClassLoader().loadClass("test.TestReporterImpl"); // ClassNotFoundException

in the pom executing the doclet

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <version>2.10.3</version>
    <executions>
        <execution>
            <id>run-my-doclet</id>
            <goals>
                <goal>javadoc</goal>
            </goals>
            <phase>generate-resources</phase>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>test</groupId>
            <artifactId>test-doclet-test-reporter</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>
    <configuration>
        <doclet>test.TestDoclet</doclet>
        <docletArtifact>
            <groupId>test</groupId>
            <artifactId>test-doclet</artifactId>
            <version>${project.version}</version>
        </docletArtifact>
        <additionalDependencies>
            <additionalDependency>
                <groupId>test</groupId>
                <artifactId>test-doclet-test-reporter</artifactId>
                <version>${project.version}</version>
            </additionalDependency>
        </additionalDependencies>
        <useStandardDocletOptions>false</useStandardDocletOptions>
    </configuration>
</plugin>

test-doclet-test-reporter/src/main/resources/META-INF/services/test.TestReporter

test.TestReporterImpl

You'd have to specify the directory to be included in your class path by adding the following to your POM anywhere under build. This is true for your classes under the meta-inf folder under resource, in cases of bugs to pick up from the default implicit resource folder.

 <project>
     ...
     <build>
       ...
       <resources>
         <resource>
           <directory>[your folder containing the class or to be in the classpath here]</directory>
         </resource>
       </resources>
       ...
     </build>
     ...
    </project>

I had a similar problem with a multi-release jar providing Doclet implementations for Java 8 and Java9+. I used the javadoc plugin option docletPath :

                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <id>javadoc9-test1</id>
                        <goals>
                            <goal>javadoc-no-fork</goal>
                        </goals>
                        <phase>test</phase>
                        <configuration>
                            <doclet>de.ohmesoftware.javadoctoproperties.Converter9</doclet>
                            <additionalOptions>-prefix rest.description -output mydocs.properties</additionalOptions>
                            <debug>true</debug>
                            <docletPath>${project.build.outputDirectory}/META-INF/versions/9</docletPath>
                            <sourcepath>${project.basedir}/src/test/java/de/ohmesoftware/javadoctoproperties/model
                            </sourcepath>
                        </configuration>
                    </execution>
             <configuration>
                    <useStandardDocletOptions>false</useStandardDocletOptions>
                    <javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
                </configuration>
            </plugin>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM