项目启动报错
java.lang.NoClassDefFoundError
解决方案
输入mvn dependency:tree命令,查看依赖信息
在这里插入代码片
| +- io.vertx:vertx-core:jar:4.3.5:compile
[INFO] | | +- io.netty:netty-common:jar:4.1.85.Final:compile
[INFO] | | +- io.netty:netty-transport:jar:4.1.85.Final:compile
[INFO] | | +- io.netty:netty-handler:jar:4.1.85.Final:compile
[INFO] | | +- io.netty:netty-handler-proxy:jar:4.1.85.Final:compile
[INFO] | | | \- io.netty:netty-codec-socks:jar:4.1.85.Final:compile
[INFO] | | +- io.netty:netty-codec-http:jar:4.1.85.Final:compile
[INFO] | | +- io.netty:netty-codec-http2:jar:4.1.85.Final:compile
[INFO] | | +- io.netty:netty-resolver:jar:4.1.85.Final:compile
[INFO] | | \- io.netty:netty-resolver-dns:jar:4.1.85.Final:compile
[INFO] | | \- io.netty:netty-codec-dns:jar:4.1.85.Final:compile
[INFO] | +- io.vertx:vertx-web:jar:4.3.5:compile
[INFO] | | +- io.vertx:vertx-web-common:jar:4.3.5:compile
[INFO] | | +- io.vertx:vertx-auth-common:jar:4.3.5:compile
[INFO] | | \- io.vertx:vertx-bridge-common:jar:4.3.5:compile
[INFO] | +- io.vertx:vertx-auth-jwt:jar:4.3.5:compile
[INFO] | +- io.vertx:vertx-web-client:jar:4.3.5:compile
[INFO] | | \- io.vertx:vertx-uri-template:jar:4.3.5:compile
[INFO] | +- io.vertx:vertx-json-schema:jar:4.3.5:compile
[INFO] | +- io.vertx:vertx-mqtt:jar:4.3.5:compile
[INFO] | | \- io.netty:netty-codec-mqtt:jar:4.1.85.Final:compile
[INFO] | +- io.vertx:vertx-hazelcast:jar:4.3.5:compile
[INFO] | | \- com.hazelcast:hazelcast:jar:4.2.5:compile
[INFO] | +- io.vertx:vertx-codegen:jar:4.3.5:compile
[INFO] | +- io.vertx:vertx-sql-client-templates:jar:4.3.5:compile
[INFO] | | \- io.vertx:vertx-sql-client:jar:4.3.5:compile
[INFO] | +- io.vertx:vertx-jdbc-client:jar:4.3.5:compile
[INFO] | | \- com.mchange:c3p0:jar:0.9.5.5:compile
[INFO] | | \- com.mchange:mchange-commons-java:jar:0.2.19:compile
[INFO] | +- io.vertx:vertx-http-proxy:jar:4.3.5:compile
[INFO] | +- io.vertx:vertx-micrometer-metrics:jar:4.3.5:compile
[INFO] | | +- io.micrometer:micrometer-core:jar:1.9.5:compile
[INFO] | | | \- org.latencyutils:LatencyUtils:jar:2.0.3:runtime
[INFO] | | \- org.hdrhistogram:HdrHistogram:jar:2.1.12:compile
[INFO] | +- io.micrometer:micrometer-registry-prometheus:jar:1.9.5:compile
[INFO] | | \- io.prometheus:simpleclient_common:jar:0.15.0:compile
[INFO] | | \- io.prometheus:simpleclient:jar:0.15.0:compile
[INFO] | | +- io.prometheus:simpleclient_tracer_otel:jar:0.15.0:compile
[INFO] | | | \- io.prometheus:simpleclient_tracer_common:jar:0.15.0:compile
[INFO] | | \- io.prometheus:simpleclient_tracer_otel_agent:jar:0.15.0:compile
[INFO] | +- org.xerial:sqlite-jdbc:jar:3.36.0.3:compile
[INFO] | +- org.apache.logging.log4j:log4j-api:jar:2.17.2:compile
[INFO] | +- org.apache.skywalking:apm-toolkit-log4j-2.x:jar:8.12.0:compile
[INFO] | +- org.apache.skywalking:apm-toolkit-trace:jar:8.12.0:compile
[INFO] | +- org.apache.logging.log4j:log4j-core:jar:2.17.2:compile
[INFO] | +- org.slf4j:slf4j-simple:jar:1.7.36:compile
[INFO] | +- javax.xml.bind:jaxb-api:jar:2.4.0-b180830.0359:compile
[INFO] | | \- javax.activation:javax.activation-api:jar:1.2.0:compile
[INFO] | +- javax.activation:activation:jar:1.1.1:compile
[INFO] | +- org.glassfish.jaxb:jaxb-runtime:jar:4.0.0:compile
[INFO] | | \- org.glassfish.jaxb:jaxb-core:jar:4.0.0:compile
[INFO] | | +- jakarta.xml.bind:jakarta.xml.bind-api:jar:4.0.0:compile
[INFO] | | +- jakarta.activation:jakarta.activation-api:jar:2.1.0:compile
[INFO] | | +- org.eclipse.angus:angus-activation:jar:1.0.0:runtime
[INFO] | | +- org.glassfish.jaxb:txw2:jar:4.0.0:compile
[INFO] | | \- com.sun.istack:istack-commons-runtime:jar:4.1.1:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-core:jar:2.13.3:compile
[INFO] | +- org.apache.commons:commons-lang3:jar:3.12.0:compile
[INFO] | +- org.jetbrains:annotations:jar:13.0:compile
[INFO] | +- io.netty:netty-transport-native-kqueue:jar:osx-x86_64:4.1.85.Final:compile
[INFO] | | +- io.netty:netty-transport-native-unix-common:jar:4.1.85.Final:compile
[INFO] | | \- io.netty:netty-transport-classes-kqueue:jar:4.1.85.Final:compile
[INFO] | +- io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.85.Final:compile
[INFO] | | \- io.netty:netty-transport-classes-epoll:jar:4.1.85.Final:compile
[INFO] | +- com.hazelcast:hazelcast-kubernetes:jar:2.2.3:compile
[INFO] | \- io.vertx:vertx-mysql-client:jar:4.3.5:compile
[INFO] +- org.apache.plc4x:plc4j-api:jar:0.9.1:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-annotations:jar:2.12.5:compile
[INFO] \- org.apache.plc4x:plc4j-driver-modbus:jar:0.9.1:compile
[INFO] +- org.apache.plc4x:plc4j-spi:jar:0.9.1:compile
[INFO] | +- io.netty:netty-codec:jar:4.1.67.Final:compile
[INFO] | +- commons-beanutils:commons-beanutils:jar:1.9.4:compile
[INFO] | | \- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] | +- io.vavr:vavr:jar:0.10.4:compile
[INFO] | | \- io.vavr:vavr-match:jar:0.10.4:compile
[INFO] | \- com.github.jinahya:bit-io:jar:1.4.3:compile
[INFO] +- org.apache.plc4x:plc4j-transport-tcp:jar:0.9.1:compile
[INFO] +- org.apache.plc4x:plc4j-transport-serial:jar:0.9.1:compile
[INFO] | \- com.fazecast:jSerialComm:jar:2.7.0:compile
[INFO] +- org.apache.plc4x:plc4j-transport-raw-socket:jar:0.9.1:compile
[INFO] | +- org.apache.plc4x:plc4j-transport-pcap-shared:jar:0.9.1:compile
[INFO] | +- org.apache.plc4x:plc4j-utils-raw-sockets:jar:0.9.1:compile
[INFO] | | +- org.pcap4j:pcap4j-core:jar:1.8.2:compile
[INFO] | | | \- net.java.dev.jna:jna:jar:5.3.1:compile
[INFO] | | \- org.pcap4j:pcap4j-packetfactory-static:jar:1.8.2:runtime
[INFO] | \- org.apache.plc4x:plc4j-utils-pcap-shared:jar:0.9.1:compile
[INFO] \- io.netty:netty-buffer:jar:4.1.67.Final:compile
以上可以看到netty架包有两个版本4.1.85,4.1.67。
解决方案1
<dependency>
<groupId>org.apache.plc4x</groupId>
<artifactId>plc4j-driver-modbus</artifactId>
<version>${plc4j.modebus.version}</version>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-buffer</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-codec</artifactId>
</exclusion>
</exclusions>
</dependency>
解决方案2
若多个架包有冲突,需要一一排除,可以在外指定使用哪个版本的架包。
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-buffer</artifactId>
<version>4.1.85.Final</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec</artifactId>
<version>4.1.85.Final</version>
</dependency>
这样项目就可以运行起来了。