当我们运行 mvn compile 时,编译器会从类路径中的各种 jar 中选择要加载的类。我想为此类加载打印“类:jar”组合列表。
先感谢您。
当我们运行 mvn compile 时,编译器会从类路径中的各种 jar 中选择要加载的类。我想为此类加载打印“类:jar”组合列表。
先感谢您。
提供 -verbose 作为编译器插件的参数。
您可以在此处交叉检查 Maven 文档
<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)]]
如果您想永久配置您的项目以打印类加载,那么接受的答案是好的。但是,您也可以使用MAVEN_OPTS
环境变量将-verbose
标志添加为一次性解决方案,如下所示:
MAVEN_OPTS="-verbose" mvn compile
在 Windows 上,您可以执行以下操作:
set MAVEN_OPTS="-verbose"
然后运行 mvn 命令
不知道它是否有帮助,但mvn dependency:tree
它会给你一个依赖 jar 树