版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yikong2yuxuan/article/details/80556790
在构建之前,需要安装开发环境:JDK和Apache Maven以及IDE。
pom文件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.netty/netty-all -->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.9.Final</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
运行构建
①在项目名上右键,run as -> mvn clean
将会输出一系列代码日志。如果出现 BUILD SUCCESS说明成功。
运行Echo服务器和客户端
①并排打开两个控制台窗口(cmd)
②一个进到netty\Server目录中,另一个进到netty\Client目录中。
③执行命令运行服务端 mvn exec:java -Dexec.mainClass="netty.server.EchoServer" -Dexec.args="9999"
④执行命令运行客户端 mvn exec:java -Dexec.mainClass="netty.client.EchoClient" -Dexec.args="localhost 9999"
如果出现“Server received:Netty rocks”说明成功