在打包一個(gè)netty框架做的后臺(tái)服務(wù)端程序的時(shí)候甥郑,一開(kāi)始用正常的maven打jar包部署到服務(wù)器上運(yùn)行報(bào)錯(cuò)悼嫉,說(shuō)找不到netty依賴(lài)文虏,后來(lái)發(fā)現(xiàn)這里需要用到fatJar插件或者-cp的方式自己添加第三方依賴(lài)节视。這里用了第一種方式论皆,需要添加fatJar的maven依賴(lài)孤钦。
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<archive>
<manifest>
<mainClass>com.junlai.wifi.collect.HttpServer</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.junlai.wifi.collect.TcpServer</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>com.jolira</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
添加了依賴(lài)后,還要在mainClass中制定入口函數(shù)纯丸,這樣再通過(guò)maven package打包生成one-jar就可以部署運(yùn)行了