-verbose:class
您可以尝试在打开 java 选项的情况下运行您的代码。这将生成输出,显示每个类的加载位置(哪个 jar 文件)。(注意:在 Sun JRE 上,这被写入标准输出;我认为在 IBM JRE 上,它被写入标准错误。)这是一个输出示例:
[Loaded junit.framework.AssertionFailedError from file:/D:/Documents%20and%20Settings/mike/.m2/repository/junit/junit/3.8.2/junit-3.8.2.jar]
[Loaded junit.framework.ComparisonFailure from file:/D:/Documents%20and%20Settings/mike/.m2/repository/junit/junit/3.8.2/junit-3.8.2.jar]
[Loaded org.jmock.core.SelfDescribing from file:/D:/Documents%20and%20Settings/mike/.m2/repository/jmock/jmock/1.2.0/jmock-1.2.0.jar]
[Loaded org.apache.log4j.spi.Configurator from file:/D:/Documents%20and%20Settings/mike/.m2/repository/log4j/log4j/1.2.9/log4j-1.2.9.jar]
[Loaded org.apache.log4j.xml.DOMConfigurator from file:/D:/Documents%20and%20Settings/mike/.m2/repository/log4j/log4j/1.2.9/log4j-1.2.9.jar]
只要您运行程序的大部分逻辑(以便加载所需的类),您就可以放心地假设verbose:class 输出中未提及的任何jar 都可以作为maven 依赖项删除。
您还可以对 verbose:class 输出进行搜索和替换,例如将其转换为 csv,然后将其放入电子表格程序中以按 jar 文件进行排序/分组。
仍然是相当多的手动工作,但至少它会给你一个开始的地方!