Netty源码编译调试

1.源码下载 从github仓库fork代码到自己的仓库 https://github.com/netty/netty,然后clone到本地。由于netty用maven进行项目管理,所以相对gradle方便很多,直接用idea打开即可
2.类不存在问题 clone代码之后,我们找到example的io.netty.example.http.websocketx.server.WebSocketServer,准备debug启动,这时候发现在codec-redis模块内的一些引包报错了

Netty源码编译调试
文章图片
image.png
进入netty-common模块下发现并没有这些类,但是有个groovy的脚本。
进入netty-common目录,运行mvn compile。发现报错

Netty源码编译调试
文章图片
image.png
发现有个netty-tools的包下载不下来 3.解决dev-tools问题 我们发现其实netty-common在编译阶段并不需要io.netty:netty-dev-tools:jar这个包,于是在父pom文件中,把这段代码注释掉

org.apache.maven.plugins maven-remote-resources-plugin 1.5 io.netty:netty-dev-tools:${project.version} ${netty.dev.tools.directory}false false process

同事在netty-common的pom.xml中去掉对dev-tools的引用
io.netty netty-dev-tools ${project.version} test true

然后在netty-common下执行 mvn clean package -Dmaven.test.skip=true,执行成功在netty-common的target下发现生成的class文件

Netty源码编译调试
文章图片
image.png 4.运行example 运行io.netty.example.http.websocketx.server.WebSocketServer,程序正常启动

Netty源码编译调试
文章图片
image.png
【Netty源码编译调试】接下来就可以边debug边看源码了

    推荐阅读