【问题标题】:Maven - find which jar class is coming fromMaven - 查找来自哪个 jar 类
【发布时间】:2021-01-22 23:39:36
【问题描述】:

我正在使用 maven 构建一个带有依赖项的 jar,当我运行该 jar 时出现错误 Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path,我从 pom.xml 中排除了所有 log4j-over-slf4j 依赖项,但仍然出现相同的错误。我尝试使用依赖树mvn dependency:tree -Dverbose -pl myModule -am > dependencytree.log,但仍然无法弄清楚这些依赖来自何处。我看到堆栈跟踪中的 org.slf4j.impl.Log4jLoggerFactory 类抛出错误,有没有办法弄清楚这个类来自哪里(哪个 jar)?

可能类似于mvn dependency:tree -Dverbose -Dincludes=<classnamehere> -pl myModule -am > logsOfBuild.log

【问题讨论】:

    标签: java maven executable-jar


    【解决方案1】:

    试试这个:

    String path = org.slf4j.impl.Log4jLoggerFactory.class.getProtectionDomain().getCodeSource().getLocation().getPath(); 
    

    这会告诉你该类所在的 jar 文件。

    【讨论】:

      猜你喜欢
      • 2012-08-10
      • 2011-05-21
      • 2010-12-31
      • 2012-10-22
      • 2010-09-16
      • 2011-04-06
      • 2016-08-04
      • 2016-07-27
      • 1970-01-01
      相关资源
      最近更新 更多