maven 由于传递依赖导致的引入低版本jar包导致classnotfind异常问题解决

maven导入jar包时,可能由于不同jar包之间依赖了不同版本的另外的jar包,会导致classnotfind异常。

举个我遇到的例子:

        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-netty-http</artifactId>
            <version>2.26</version>
        </dependency>

        <dependency>
            <groupId>org.apache.hbase</groupId>
            <artifactId>hbase-client</artifactId>
            <version>2.1.0<</version>
        </dependency>

 

如上,我引入上面两个包时,

Channel server = NettyHttpContainerProvider.createHttp2Server(BASE_URI, new APIApplication(), null);

此时执行上面的创建启动 Netty HTTP/2 server 没有问题,正常。

由于项目中需要将hbase-client版本换成1.2.6,问题就来了。

        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-netty-http</artifactId>
            <version>2.26</version>
        </dependency>

        <dependency>
            <groupId>org.apache.hbase</groupId>
            <artifactId>hbase-client</artifactId>
            <version>1.2.6<</version>
        </dependency>

 

如上,pom中需要改为上面这样。此时在我的Activator中

Channel server = NettyHttpContainerProvider.createHttp2Server(BASE_URI, new APIApplication(), null);

会报java.lang.ClassNotFoundException: io.netty.handler.codec.http.HttpServerUpgradeHandler$UpgradeCodecFactory not found异常。

原因是1.2.6中依赖了netty-all 4.0.几的一个版本,而jersey-container-netty-http2.2.6中依赖的是netty-all 4.1.5.Final这个版本。所以需要手动引入4.1.5这个版本。

即在pom文件中加入:

<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-all</artifactId>
    <version>4.1.5.Final</version>
</dependency>

至此,问题解决。

问题分析步骤:

1、程序启动时抛出异常java.lang.ClassNotFoundException: io.netty.handler.codec.http.HttpServerUpgradeHandler$UpgradeCodecFactory not found,所以可以从这个类所在的jar包开始分析;

2、查找jar包所依赖的其他jar。可参考https://blog.csdn.net/qq_35893120/article/details/78436455网上这篇文章,然后找到引用的不同版本的jar, 这里就需要分析一下,看是哪个导致的classnotfind异常。  很麻烦,但我目前还不清楚有什么好的办法。(大神看到可以回复一下)

3、手动引入高版本的jar。

水平有限,出错之处 请拍砖指正。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值