1. 程式人生 > 其它 >【Netty】Netty原始碼編譯

【Netty】Netty原始碼編譯

環境準備

  • Jdk:1.8.0_181
  • Idea:2021.1.1Community 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

  

可能出現的錯誤

  問題1:Could 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 工具進行連線