javaclassmaven-3classloaderjavacompiler

How to print class loading pattern for command "mvn compile"?


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.


Solution

  • 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)]]