1.源碼下載
從github倉庫fork代碼到自己的倉庫 https://github.com/netty/netty欣除,然后clone到本地际乘。由于netty用maven進(jìn)行項(xiàng)目管理螟蝙,所以相對(duì)gradle方便很多瑞凑,直接用idea打開即可
2.類不存在問題
clone代碼之后托享,我們找到example的io.netty.example.http.websocketx.server.WebSocketServer,準(zhǔn)備debug啟動(dòng)嫩挤,這時(shí)候發(fā)現(xiàn)在codec-redis模塊內(nèi)的一些引包報(bào)錯(cuò)了
進(jìn)入netty-common模塊下發(fā)現(xiàn)并沒有這些類,但是有個(gè)groovy的腳本消恍。
進(jìn)入netty-common目錄岂昭,運(yùn)行mvn compile。發(fā)現(xiàn)報(bào)錯(cuò)
發(fā)現(xiàn)有個(gè)netty-tools的包下載不下來
3.解決dev-tools問題
我們發(fā)現(xiàn)其實(shí)netty-common在編譯階段并不需要io.netty:netty-dev-tools:jar這個(gè)包狠怨,于是在父pom文件中约啊,把這段代碼注釋掉
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.5</version>
<configuration>
<resourceBundles>
<resourceBundle>io.netty:netty-dev-tools:${project.version}</resourceBundle>
</resourceBundles>
<outputDirectory>${netty.dev.tools.directory}</outputDirectory>
<!-- don't include netty-dev-tools in artifacts -->
<attachToMain>false</attachToMain>
<attachToTest>false</attachToTest>
</configuration>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
</plugin>
同事在netty-common的pom.xml中去掉對(duì)dev-tools的引用
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-dev-tools</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<optional>true</optional>
</dependency>
然后在netty-common下執(zhí)行 mvn clean package -Dmaven.test.skip=true,執(zhí)行成功在netty-common的target下發(fā)現(xiàn)生成的class文件
4.運(yùn)行example
運(yùn)行io.netty.example.http.websocketx.server.WebSocketServer取董,程序正常啟動(dòng)
接下來就可以邊debug邊看源碼了