Search code examples
mavendependencies

Find all imports among maven dependencies?


I am updating a maven project to Spring Boot 3 and Java 21. In doing so, I am getting this exception at runtime:

java.lang.ClassNotFoundException: javax.servlet.http.HttpServletRequest
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) ~[?:?]
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) ~[?:?]
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526) ~[?:?]
    at java.base/java.lang.Class.forName0(Native Method) ~[?:?]
    at java.base/java.lang.Class.forName(Class.java:534) ~[?:?]
    at java.base/java.lang.Class.forName(Class.java:513) ~[?:?]
    at java.base/sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114) ~[?:?]
    ... 32 more
Wrapped by: java.lang.TypeNotPresentException: Type javax.servlet.http.HttpServletRequest not present

I am not using javax.servlet.http.HttpServletRequest in my project, so I assume this is in a stale JAR. I thought there was a way to run mvn dependency:tree or a plugin for Eclipse/IJ that shows all of the imports used by each dependent JAR, such that I could see JAR xyz doing an import of this problem type and exclude or update it.

For a general case, how do I accomplish this - Finding the classes referenced by each JAR my project has as a dependency, recursively?


Solution

  • I was able to accomplish this as follows.

    1. Build my app using maven.
    2. Find the resulting JAR.
    3. Open the JAR in JD, the Java Decompiler.
    4. Use the "save all sources" option, which produces a directory of all dependency JARs.
    5. Write a script that does a foreach for each of those JARs and runs the unar command.
    6. grep -r for the offending import among the resulting Java files.