0

I have a parent project that has multiple sub modules. Whenever I run mvn package -DskipTests at the project root, some submodule breaks on not finding tools.jar in the JDK directory (Mac OS Big Sur).

After some research, I found this thread that asks to put an exclusion in the dependency that's expecting tools.jar. I fixed some modules with this solution but it isn't very scalable. My submodules have several dependencies and I have to put exclusion in all of them and build, then undo some exclusions and build again to find out which exact dependency is expecting tools.jar. I have tried running mvn dependency:tree to find out but even that fails on the same unable to find tools.jar error. Is there a simpler way to do this?

Thanks!

Sankalp
  • 1,182
  • 2
  • 17
  • 22
  • Not familiar with Maven - but I guess you should fix your classpath rather than exclude any dependency. – maio290 Jun 29 '21 at 22:19
  • Did you test using Eclipses dependency view [as suggested by me in the thread you linked](https://stackoverflow.com/a/32871694/365237)? – eis Jun 29 '21 at 22:26
  • @maio290 tools.jar is a relic from older versions of java, which really shouldn't be referred to anymore – eis Jun 29 '21 at 22:27
  • @eis - I don't use Eclipse. I use IntelliJ instead. – Sankalp Jun 29 '21 at 22:40
  • @eis Well - I wouldn't call Java 8 a relic already. – maio290 Jun 29 '21 at 22:53
  • @maio290 I didn't call java 8 a relic, I called tools.jar :) tools.jar is an artifact of older versions which did linger until java 8 until it died. Even with java 8 it hasn't been a good practice to refer to it. one of the reasons was that it has been called classes.jar on mac instead of tools.jar, causing the build to break per operating system for no reason at all. – eis Jun 30 '21 at 15:40

2 Answers2

1

One thing that helped me was this IntelliJ plugin - https://plugins.jetbrains.com/plugin/7179-maven-helper

Going to "Dependency Analyzer" and search for "com.sun" pointed me to the exact dependency.

Sankalp
  • 1,182
  • 2
  • 17
  • 22
-1

I don't think you should add tools.jar as an exclusion. I would rather suggest adding tools.jar into your JDK.

If you don't have any tools.jar, I would suggest downloading a new version of JDK, copy tools.jar from the lib folder and copy into your jdk_home/lib.

Following these steps solved my problem when I came across it.

old_soul_on_the_run
  • 279
  • 1
  • 6
  • 15