当我们运行mvn compile时,编译器选择要从类路径中的各种jar加载的类。我想为这样的类加载打印“class:jar”组合列表。
提前谢谢。
答案 0 :(得分:2)
提供-verbose作为编译器插件的参数。
您可以交叉检查maven文档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>
输出将在控制台中打印。
您可以使用mvn clean install --log-file log.txt
将其重定向到文件
编写解析器以从日志中提取所需信息。
样本输出:
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)]]
答案 1 :(得分:0)
Dunno如果它有用,但有mvn dependency:tree
它为您提供了依赖关系罐的树
答案 2 :(得分:0)
如果要永久性地配置项目以打印类加载,则可接受的答案是好的。但是,您也可以使用MAVEN_OPTS
环境变量将-verbose
标志添加为一次性解决方案,如下所示:
MAVEN_OPTS="-verbose" mvn compile