1、构建打包脚本zip_file.xml(打包zip文件,此处用不到)和pom.xml
打包libs
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<type>jar</type>
<includeTypes>jar</includeTypes>
<outputDirectory>
${project.build.directory}/libs
</outputDirectory>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
打包zip文件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-auto-deploy</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>deploy/zip_file.xml</descriptor>
</descriptors>
<finalName>nettyClient</finalName>
<outputDirectory>target</outputDirectory>
<archiverConfig>
<directoryMode>0700</directoryMode>
<fileMode>0600</fileMode>
<defaultDirectoryMode>0700</defaultDirectoryMode>
</archiverConfig>
</configuration>
</execution>
</executions>
</plugin>
2、maven clean install,打包效果如下:
内层的libs从外层的libs复制进来,并不是打包产生
3、在classes路径下,运行cmd
4、windows环境下 classess路径下运行命令:java -cp .;libs/* com.huawei.netty.RtkClient
linux环境下运行:java -cp .:libs/* com.huawei.netty.RtkClient ,分号变成冒号
这里的 -cp 表示 -classpath .;的含义为当前目录加入classpath
原文:https://www.cnblogs.com/irvin-chen/p/14597500.html