Java报错:java.lang.NoSuchMethodError: io.netty.util.internal.ObjectUtil.checkPositive

一、产生原因:版本冲突

做第一个功能时引入了netty进行通信,没有问题。

做第二个功能是,引入了modbus的一个jar包,然后工程就无法启动了,提示:

java.lang.NoSuchMethodError: io.netty.util.internal.ObjectUtil.checkPositive

通过查看项目依赖,发现modbus自身也依赖netty,只是版本不一致。

查看maven依赖树命令传送门:https://www.cnblogs.com/hunttown/p/13138858.html

二、解决办法:

在引用modbus的jar包时,排除netty的引用就可以了,下面蓝色加粗部分

<dependency>
    <groupId>com.digitalpetri.modbus</groupId>
    <artifactId>modbus-master-tcp</artifactId>
    <version>${modbus.tcp.version}</version>
    <exclusions>
        <exclusion>
            <groupId>io.netty</groupId>
            <artifactId>netty-buffer</artifactId>
        </exclusion>
        <exclusion>
            <groupId>io.netty</groupId>
            <artifactId>netty-common</artifactId>
        </exclusion>
        <exclusion>
            <groupId>io.netty</groupId>
            <artifactId>netty-codec</artifactId>
        </exclusion>
        <exclusion>
            <groupId>io.netty</groupId>
            <artifactId>netty-transport</artifactId>
        </exclusion>
    </exclusions>
</dependency>

上面使用<exclusions></exclusions>标签进行排除。

原文地址:https://www.cnblogs.com/hunttown/p/13637595.html