一、源码阅读环境搭建
1.环境信息
- 机器环境:win10 64位
- Oracle Java8 : 1.8.0_251
- 开发工具:IntelliJ IDEA
- netty源码版本: netty-4.1.55.Final
2.下载源码
下载代码,可以用gitee加速
git clone https://github.com/netty/netty.git
切换到指定分支
git checkout netty-4.1.55.Final
3.导入idea cmd
3.1 使用idea直接打开源码目录
提前配置好idea新建工程的maven配置
3.2在maven的profile中勾选如下,导入后没改过
3.3 执行install
点击图标让mvn跳过测试(test就会显示删除线)。再双击install进行编译
3.3.1 netty-common 编译签名错误
Failed to execute goal org.codehaus.mojo:animal-sniffer-maven-plugin:1.16:check (default) on project netty-common: Signature errors found. Verify them and ignore them with the proper annotation if needed.
按提示可以选择注释animal-sniffer-maven-plugin
3.3.2 代码风格校验失败
Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.1.0:check (nohttp-checkstyle-validation) on project netty-parent: You have 1 Checkstyle violation.
直接注释掉:maven-checkstyle-plugin
3.3.3 报错java: 对assertEquals的引用不明确
netty-transport 编译抱错,但是idea显示日志乱码
通过在控制台执行命令netty\transport>mvn -DskipTests=true install
,发现错误日志如下:
对assertEquals的引用不明确
Assert 中的方法 assertEquals(long,long) 和 Assert 中的方法 assertEquals(Object,Object) 都匹配
有报错的地方直接加强转,官网master就是这么干的
//PendingWriteQueueTest.java:263:9
assertEquals(1L, (long) channel.readOutbound());
//ByteToMessageCodecTest.java:65:9
assertEquals(1, (int) ch.readInbound());
//ByteToMessageDecoderTest.java:505:9
assertEquals((byte) 1, (byte) channel.readInbound());
//ChunkedWriteHandlerTest、FlushConsolidationHandlerTest
3.3.4 netty-codec-http 检测Api不兼容
Failed to execute goal com.github.siom79.japicmp:japicmp-maven-plugin:0.14.3:cmp (default) on project netty-codec-http: There is at least one incompatibility: io.netty.handler.codec.http.multipart.AbstractDiskHttpData:METHOD_ABSTRACT_ADDED_IN_IMPLEMENTED_INTERFACE,io.netty.handler.codec.http.multipart.AbstractMemoryHttpData:METHOD_ABSTRACT_ADDED_IN_IMPLEMENTED_INTERFACE
那就跳过检查,把false
改为true
4.运行EchoServer和EchoClient
完整类名io.netty.example.echo.EchoServer,io.netty.example.echo.EchoClient
4.1 EchoServer运行日志
4.2 运行时可以有选择的把Client和Server的日志打印Handler取消注释
R1.参考资料
https://segmentfault.com/a/1190000022319237?utm_source=tag-newest