当前位置: 代码迷 >> 综合 >> Mac 下 Netty 4.1 代码编译与运行
  详细解决方案

Mac 下 Netty 4.1 代码编译与运行

热度:61   发布时间:2023-12-01 12:25:26.0

一、基本环境

1、本地环境

  • JDK 1.8,64位

? ~ java -version
java version “1.8.0_271”
Java? SE Runtime Environment (build 1.8.0_271-b09)
Java HotSpot? 64-Bit Server VM (build 25.271-b09, mixed mode)

  • IDEA 64位

查看版本
在这里插入图片描述

版本信息
在这里插入图片描述

  • Mac 操作系统

dasd

  • Maven 环境

Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-18T02:33:14+08:00)
Maven home: /xx/apache-maven-3.5.4
Java version: 1.8.0_271, vendor: Oracle Corporation, runtime: /xx/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: “mac os x”, version: “10.16”, arch: “x86_64”, family: "Mac


环境参考:https://github.com/netty/netty/wiki/Setting-up-development-environment

源码下载地址:https://github.com/netty/netty


二、编译

运行编译命令:

mvn install -Dmaven.test.skip=true -Dcheckstyle.skip=true

查看具体出错的位置:

mvn -U -X clean package

1、结果

netty 编译结果
在这里插入图片描述


2、核心包

netty 中的包,主要可以分为下面三个部分

  • Transport
    • ? TCP/UDP:对于TCP而言,它可能有不同的native实现,如:epoll(Linux)、kqueue(Mac)、common(Unix)
    • SCTP

  • Protocol
    • 编解码:粘包、半包、协议支持
    • handler

  • 工具类
    • buffer
    • common
    • resolver

3、常见问题

  • Requested download does not exist
[ERROR] Failed to execute goal org.fusesource.hawtjni:maven-hawtjni-plugin:1.14:build (build-native-lib) on project netty-transport-native-kqueue: build failed: org.apache.maven.plugin.MojoExecutionException: Requested download does not exist.: Could not find artifact io.netty:netty-transport-native-kqueue:zip:native-src:4.1.64.Final-SNAPSHOT in sonatype-nexus-snapshots (https://oss.sonatype.org/content/repositories/snapshots)

解决方法:

brew install autoconf automake libtool
  • Could not find artifact io.netty:netty-tcnative:jar:xxxxxx in central
    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-YDhRb7TJ-1618555891456)(/Users/heguitang/Library/Application Support/typora-user-images/image-20210329123600184.png)]

解决方法:手动执行 tcnative.classifier 版本(如:windows),不依靠netty的自动检测

<!--<tcnative.classifier>${os.detected.classifier}</tcnative.classifier>
-->
<tcnative.classifier>windows-x86_64</tcnative.classifier>
  • Error:(18,31) java: 错误: 程序包io.netty.util.collection不存在

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Y9WyJHE0-1618555891457)(/Users/heguitang/Library/Application Support/typora-user-images/image-20210329125051439.png)]

解决方法:单独编译一下 netty-common 模块

linux 下 可以使用 mvn compile -Dcheckstyle.skip=true -e 生成 io.netty.util.collection

  • check-style
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] .........
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.12.1:check (check-style) on project netty-common: Failed during checkstyle execution: There are 314 checkstyle errors. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionExceptionProcess finished with exit code 1

原因:git将会根据使用者的系统自动将下载项目中的换行符转换成系统的换行符,如果使用 Download Zip 方式下载项目的话会遇到这类问题。

解决方法: 使用 Git clone 命令下载源码