Java 将自定义netty编解码器与maven一起使用时出现NoSuchMethodError(编译器目标为1.8)
我正在维护一个基于netty的httpServer库,它使用定制的Java 将自定义netty编解码器与maven一起使用时出现NoSuchMethodError(编译器目标为1.8),java,maven,netty,Java,Maven,Netty,我正在维护一个基于netty的httpServer库,它使用定制的netty编解码器http。该库应该适用于java版本>=8。它在Java12上运行良好,但在Java8上不起作用。有人能帮忙让它在java8上工作吗 我知道问题很可能与java9上对ByteBuffer接口的更改有关。然而,我无法让它工作。到目前为止我都试过了 在java8上构建netty编解码器http和httpServer库(编译器源代码和目标设置为1.8)并在java8上运行 在java12(编译器源代码=12,目标代码=
netty编解码器http
。该库应该适用于java版本>=8。它在Java12上运行良好,但在Java8上不起作用。有人能帮忙让它在java8上工作吗
我知道问题很可能与java9上对ByteBuffer接口的更改有关。然而,我无法让它工作。到目前为止我都试过了
netty编解码器http
和httpServer库(编译器源代码和目标设置为1.8)并在java8上运行java.lang.NoSuchMethodError: java.nio.ByteBuffer.clear()Ljava/nio/ByteBuffer;
at io.netty.buffer.PooledByteBuf.internalNioBuffer(PooledByteBuf.java:158)
at io.netty.buffer.PooledByteBuf._internalNioBuffer(PooledByteBuf.java:188)
at io.netty.buffer.PooledByteBuf.internalNioBuffer(PooledByteBuf.java:201)
at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:253)
at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1133)
at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:350)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:148)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:745)
Maven设置
//version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/Cellar/maven/3.6.3_1/libexec
Java version: 13.0.2, vendor: N/A, runtime: /usr/local/Cellar/openjdk/13.0.2+8_2/libexec/openjdk.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.4", arch: "x86_64", family: "mac"
//command
cd /../netty
mvn clean install -pl codec-http -am
netty编解码器http pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.netty</groupId>
<artifactId>netty-parent</artifactId>
<version>4.1.49.Final</version>
</parent>
<artifactId>netty-codec-http</artifactId>
<packaging>jar</packaging>
<version>4.1.49.Final.custom.1.0.0-SNAPSHOT</version>
<name>Netty/Codec/HTTP</name>
<properties>
<javaModuleName>io.netty.codec.http</javaModuleName>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-common</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-buffer</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-transport</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-codec</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>netty-handler</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jzlib</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
</dependencies>
</project>
<project //...>
//...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec-http</artifactId>
<version>4.1.49.Final.custom.1.0.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.49.Final</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>2.0.30.Final</version>
<classifier>linux-x86_64</classifier>
</dependency>
</dependencies>
</project>
这是使用java9+编译并使用java8运行的结果。原因是,在java9中,ByteBuffer重写了一些方法,例如flip(),并返回ByteBuffer,而java8则返回Buffer。用jdk8重新编译代码,问题应该会得到解决。我以前试过,但现在我要再试一次。但是maven.compiler.target=1.8不应该已经处理了吗?这是API的变化。target仅控制类文件的输出格式。但是,根据,maven.compiler.release应该这样做。当然,您需要maven编译插件版本3.8.0及更高版本。