1

When we run, mvn compile, compiler picks the classes to load from various jars in classpath. I want to print the list of "class : jar" combination for such class loading.

Thank you in advance.

sagar borse
  • 155
  • 1
  • 2
  • 11
  • Right now, I found this unclear. What do you want exactly, what have you tried, or what would you tried. This could be good to have some example – AxelH Feb 08 '17 at 07:52

3 Answers3

2

Provide -verbose as argument to the compiler plugin.

You can cross check the maven documentation here

            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
                    <configuration>
                        <compilerArgs>
                            <arg>-verbose</arg>

                    </compilerArgs>
             </configuration>
        </plugin>

Output will get printed in console . You can redirect it to file using mvn clean install --log-file log.txt Write a parser to extract the required information from the logs. Sample output :

loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_101\lib\ct.sym(META-INF/sym/rt.jar/java/lang/Object.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_101\lib\ct.sym(META-INF/sym/rt.jar/java/util/logging/Level.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_101\lib\ct.sym(META-INF/sym/rt.jar/java/util/logging/Logger.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_101\lib\ct.sym(META-INF/sym/rt.jar/java/lang/String.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_101\lib\ct.sym(META-INF/sym/rt.jar/java/io/UnsupportedEncodingException.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_101\lib\ct.sym(META-INF/sym/rt.jar/java/net/URLDecoder.class)]]
[loading ZipFileIndexFileObject[C:\m2_repo\javax\ws\rs\javax.ws.rs-api\2.0\javax.ws.rs-api-2.0.jar(javax/ws/rs/core/Response.class)]]
[loading ZipFileIndexFileObject[C:\m2_repo\javax\ws\rs\javax.ws.rs-api\2.0\javax.ws.rs-api-2.0.jar(javax/ws/rs/ext/ExceptionMapper.class)]]
[loading ZipFileIndexFileObject[C:\m2_repo\javax\ws\rs\javax.ws.rs-api\2.0\javax.ws.rs-api-2.0.jar(javax/ws/rs/ext/Provider.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_101\lib\ct.sym(META-INF/sym/rt.jar/java/lang/RuntimeException.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_101\lib\ct.sym(META-INF/sym/rt.jar/java/util/HashSet.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_101\lib\ct.sym(META-INF/sym/rt.jar/java/util/Set.class)]]
[loading ZipFileIndexFileObject[C:\m2_repo\javax\ws\rs\javax.ws.rs-api\2.0\javax.ws.rs-api-2.0.jar(javax/ws/rs/ApplicationPath.class)]]
[loading ZipFileIndexFileObject[C:\m2_repo\javax\ws\rs\javax.ws.rs-api\2.0\javax.ws.rs-api-2.0.jar(javax/ws/rs/core/Application.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_101\lib\ct.sym(META-INF/sym/rt.jar/java/lang/Class.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_101\lib\ct.sym(META-INF/sym/rt.jar/java/util/ArrayList.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_101\lib\ct.sym(META-INF/sym/rt.jar/java/util/Collection.class)]]
[loading ZipFileIndexFileObject[C:\m2_repo\javax\annotation\javax.annotation-api\1.2\javax.annotation-api-1.2.jar(javax/annotation/security/RolesAllowed.class)]]
[loading ZipFileIndexFileObject[C:\m2_repo\javax\ws\rs\javax.ws.rs-api\2.0\javax.ws.rs-api-2.0.jar(javax/ws/rs/GET.class)]]
[loading ZipFileIndexFileObject[C:\m2_repo\javax\ws\rs\javax.ws.rs-api\2.0\javax.ws.rs-api-2.0.jar(javax/ws/rs/Path.class)]]
[loading ZipFileIndexFileObject[C:\m2_repo\javax\ws\rs\javax.ws.rs-api\2.0\javax.ws.rs-api-2.0.jar(javax/ws/rs/Produces.class)]]
[loading ZipFileIndexFileObject[C:\m2_repo\javax\ws\rs\javax.ws.rs-api\2.0\javax.ws.rs-api-2.0.jar(javax/ws/rs/QueryParam.class)]]
[loading ZipFileIndexFileObject[C:\m2_repo\javax\ws\rs\javax.ws.rs-api\2.0\javax.ws.rs-api-2.0.jar(javax/ws/rs/core/Context.class)]]
[loading ZipFileIndexFileObject[C:\m2_repo\javax\ws\rs\javax.ws.rs-api\2.0\javax.ws.rs-api-2.0.jar(javax/ws/rs/core/MediaType.class)]]
[loading ZipFileIndexFileObject[C:\m2_repo\javax\ws\rs\javax.ws.rs-api\2.0\javax.ws.rs-api-2.0.jar(javax/ws/rs/core/SecurityContext.class)]]
[loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_101\lib\ct.sym(META-INF/sym/rt.jar/java/lang/Exception.class)]]
Sumit Kumar
  • 375
  • 1
  • 11
  • How does this differ from normal compilation (except for redirecting output to log)? You seems to missed important part of configuration. – rkosegi Feb 08 '17 at 08:39
  • Without any configuration it is coming in output . I just checked. A parser can be written to parse this file and get the required information. – Sumit Kumar Feb 08 '17 at 08:41
  • Will cross check one time and will add the required configuration. – Sumit Kumar Feb 08 '17 at 08:46
  • 2
    you need to include `-verbose` flag as described here : https://maven.apache.org/plugins/maven-compiler-plugin/examples/pass-compiler-arguments.html. Fix your answer and I will remove downvote. – rkosegi Feb 08 '17 at 08:48
  • Thanks i was just trying that. – Sumit Kumar Feb 08 '17 at 08:52
1

If you want to permanently configure your project to print the class loading then the accepted answer is good. However, you can also use the MAVEN_OPTS environment variable to add the -verbose flag as a one off solution, like so:

MAVEN_OPTS="-verbose" mvn compile

On windows you can do it like below: set MAVEN_OPTS="-verbose" and then run mvn command

Kapil
  • 817
  • 2
  • 13
  • 25
webdavis
  • 83
  • 1
  • 5
0

Dunno if its helpful but there is mvn dependency:tree which gives you a tree of dependency jars

https://maven.apache.org/plugins/maven-dependency-plugin/examples/resolving-conflicts-using-the-dependency-tree.html

Zeromus
  • 4,472
  • 8
  • 32
  • 40