Packaging custom javadoc doclet with maven

codewing

I've written my own java doclet and want to package it into a single jar file to use it later on.

I'm currently using maven with these settings to generate it:

<build>
    <finalName>Doclet</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.3.1</version>
            <configuration>
              <archive>
                <manifest>
                  <addClasspath>true</addClasspath>
                  <mainClass>de.test.tools.doclet.Doclet</mainClass>
                </manifest>
              </archive>
            </configuration>
        </plugin>

        <!-- Maven Assembly Plugin -->
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <id>make-my-jar-with-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>

                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>de.test.tools.doclet.Doclet</mainClass>
                    </manifest>
                </archive>

                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>

            </configuration>
        </plugin>
    </plugins>
</build>

Problem:
Everything is properly packaged into the jar but my sources are missing.
If I try to do a simple mvn package it tells me that the sun package doesn't exist.

error: package com.sun.javadoc does not exist

I think the last part is the main reason behind why I can't find my sources in the jar and thus my question is how I can tell maven to ignore those imports.

codewing

The problem is that maven cannot find package com.sun.javadoc which is in the tools.jar in the /lib folder of the java installation dir.

Eclipse was able to execute it because I added it to the classpath there but maven had no idea where he can get the resources from. So adding the following system dependency solved the problem for me:

<dependency>
    <scope>system</scope>
    <groupId>com.sun</groupId>
    <artifactId>tools</artifactId>
    <version>YOUR_JAVA_VERSION</version>
    <systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>

Replace the version with your version and make sure java home is known in your environment.

Note: This dependency doesn't work on MacOS. See: JDK tools.jar as maven dependency - Summary: Use Profiles for each OS to be able to specify the correct path.

I only need to support Linux + Windows so it is the best solution for me.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related