【Netty】Netty源碼編譯


環境准備

  • 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 工具進行連接

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM