H__D  

环境准备

  • Jdk:1.8.0_181
  • Idea:2021.1.1 Community Edition(社区版)
  • Maven:3.6.3

1、下载Netty源码

  本例下载的是 netty-4.1.63.Final

2、使用Idea打开项目,进行编译

  • 导入Idea:File --> Open --> 选择Netty项目目录 netty-4.1.63.Final

  

  • 等待索引建立完成,在控制台输入命令:mvn clean package -DskipTests=true

  

可能出现的错误

  问题1Could not find artifact io.netty:netty-tcnative:jar:${os.detected.classifier}:2.0.38.Final in central (https://repo.maven.apache.org/maven2)

  分析:maven无法获取${os.detected.classifier}的问题,参考:https://blog.csdn.net/weixin_43962314/article/details/108933596

  解决:添加Maven运行参数

  windows系统:命令行运行增加: -Dos.detected.classifier=windows-x86_64

  Linux系统:命令行运行增加: -Dos.detected.classifier=linux-x86_64

  Mac系统:命令行运行增加: -Dos.detected.classifier=osx-x86_64

  

  或者在pom文件中,增加属性:<os.detected.classifier>osx-x86_64</os.detected.classifier>

  问题2[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run (build-native-lib) on project netty-transport-native-unix-common: An Ant BuildException has occured: exec returned: 1

  [ERROR] around Ant part ...<exec resolveexecutable="true" failonerror="true" executable="make">... @ 4:71 in /Users/h__d/Documents/git-repository/netty-4.1.63.Final/transport-native-unix-common/target/antrun/build-main.xml

  分析:maven-antrun-plugin插件需要执行命令 make,检查make命令是否可用,参考:https://blog.csdn.net/weixin_33849215/article/details/90685367

  解决:修复 make 命令

  

   问题3: maven-remote-resources-plugin 插件,无法加载到远程资源

  解决:直接在pom文件中,将代码注释

<!--      <plugin>-->
<!--        <groupId>org.apache.maven.plugins</groupId>-->
<!--        <artifactId>maven-remote-resources-plugin</artifactId>-->
<!--        <version>1.5</version>-->
<!--      </plugin>--> 

3、测试运行示例

  1、运行example项目中的,src/main/java/io/netty/example/http/cors/HttpCorsServer.java,运行文件main方法

  2、效果如下:

  

  3、可以使用telnet 工具进行连接

  

 

posted on 2021-06-17 03:15  H__D  阅读(1347)  评论(0编辑  收藏  举报