0

Based on JDK11 restructuring of tools.jar I was trying to exclude it from a POM dependency as follows

<profile>
    <id>exclude-if-jdk11</id>
    <activation>
        <jdk>11</jdk>
    </activation>
    <properties>
       <!-- bla bla bla -->
    </properties>
    <dependencies>
    <dependency>
    <groupId>com.internal.mypomz</groupId>
    <artifactId>mypomext</artifactId>
    <type>pom</type>
    <version>1.1</version>
    <exclusions>
        <exclusion>
            <groupId>jdom</groupId>
            <artifactId>jdom</artifactId>
        </exclusion>
        <exclusion>
            <groupId>com.sun</groupId>
            <artifactId>tools</artifactId>
        </exclusion>
    </exclusions>
</dependency>
</dependencies>
</profile>  

Despite the above, I am getting the error that tools.jar cannot be found in JDK11/bin folder. But I was expecting that this jar lookup will be skipped. Is there something I've configured incorrectly?

ha9u63a7
  • 6,233
  • 16
  • 73
  • 108
  • Have a look at `mvn dependency:tree` with and without the profile activated. – J Fabian Meier Feb 05 '20 at 10:26
  • I would suggest to refactor your code and get rid of tools things like this...and solve it at the root not via exclusion...furthermore your dependency is of type `pom` which does not has dependencies only a jar can have dependencies ...and having profiles for different dependencies is in general a bad idea... – khmarbaise Feb 05 '20 at 12:07
  • @khmarbaise One step at a time... :) Also, we are not having profile for dependencies, the profile is active only when we have JDK11 on the platform. So it's not that brittle. I agree with what you said about exclusions, hence, removed them entirely without profiles. – ha9u63a7 Feb 05 '20 at 12:16

1 Answers1

0

After a bit of digging, we found out that there was a war dependency which was also fetching tools.jar. So yes, the fix was using mvn dependency:tree first we checked who is fetching the jars. Then exclude them individually, until mvn dependency:tree shows no evidence of that.

We got it to work with both JDK11 and JDK8. Also, as update to the profile body posted in the question, we have now excluded all tools.jar from the POM and it is more manageable.

ha9u63a7
  • 6,233
  • 16
  • 73
  • 108