遇到一个问题,在用IDEA写好Java 代码之后,在IDEA运行没有问题,但是用maven打成jar包再运行的时候,却报缺失依赖包的情况
解决办法,使用Maven-shade-plugin这个插件来打包
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<!-- 这里必须要填下面这段,否则报错 -->
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<!-- 下面这里要填要运行的类,否则会报错 -->
<mainClass>com.corsface.ServerDemo</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>