Gradle 导入本地 jar, Springboot 启动时和引入的 jar 中的 slf4j 冲突 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
请不要在回答技术问题时复制粘贴 AI 生成的内容
stephCurry
V2EX    程序员

Gradle 导入本地 jar, Springboot 启动时和引入的 jar 中的 slf4j 冲突

  •  
  •   stephCurry 2019-09-19 23:45:08 +08:00 2552 次点击
    这是一个创建于 2281 天前的主题,其中的信息可能已经有所发展或是发生改变。

    SpringBoot 项目导入了本地特别的 jar, 通过 build.gradle 方式如下:

    dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' ...省略 compile files("libs/myjar.jar") } 

    然后启动 SpringBoot 时提示 slf4j 冲突如下:

    SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/thePath/myjar.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/Users/user/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.2.3/7c4f3c474fb2c041d8028740440937705ebb473a/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory] Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.SimpleLoggerFactory loaded from file:/Users/pop/projects/cncert/vehicle-engine/libs/DexKiller.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.SimpleLoggerFactory 

    然而尝试了 gradle exclude 也不好使。。。尝试如下:

    dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' ...省略 compile files("libs/myjar.jar"){ exclude group(或者 module):"org.slf4j" } } 

    然后随后把打成 jar 的工程里的直接用到 Logutils 都删了, 重新打包后查看 jar 里面资源, 还是有 org.slf4j, 可能是引用其他工具包的必要依赖吧。

    v 友有解决方法吗?

    7 条回复    2019-10-17 17:29:43 +08:00
    rb6221
        1
    rb6221  
       2019-09-20 11:10:02 +08:00
    gradle 有全局的 exclude,不要在某个特定的包下面 exclude
    stephCurry
        2
    stephCurry  
    OP
       2019-09-20 15:35:55 +08:00
    @janus77 感谢解答,但是如果全局 exclude 那把 springboot 的 slf4j 也 exclude 掉了啊
    C02TobNClov1Dz56
        3
    C02TobNClov1Dz56  
       2019-09-20 15:54:03 +08:00
    本地的 jar 对吧, 如果没有签名, 可以直接把本地 jar 的 slf4j 相关 class 和 package 都删了.
    C02TobNClov1Dz56
        4
    C02TobNClov1Dz56  
       2019-09-20 15:54:55 +08:00
    可以用 7zip 之类的软件打开 jar 包, 或者直接改后缀名为 zip
    wei745359223
        5
    wei745359223  
       2019-10-17 16:49:46 +08:00   1
    增加这段试试
    configurations {
    compile.exclude module: 'spring-boot-starter-logging'
    }

    dependencies {
    ....
    }
    stephCurry
        6
    stephCurry  
    OP
       2019-10-17 17:02:33 +08:00
    @wei745359223 谢谢, 但是我想 exclude 的是被引用 jar 的 slf4j, 但是那个 jar 中的 slf4 无法 exclude, 因为那个 jar 里面的 package 里就有 org.slf4j, 好像除了找到那个文件源码删除有关 slf4j 的部分, 别无它法?
    stephCurry
        7
    stephCurry  
    OP
       2019-10-17 17:29:43 +08:00
    找到了这个 jar 文件源码, 但是看了下通过修改源码的方式放弃了。。。。
    https://github.com/secure-software-engineering/FlowDroid/releases#soot-infoflow-cmd-jar-with-dependencies.jar
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     5312 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 24ms UTC 06:49 PVG 14:49 LAX 22:49 JFK 01:49
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86