maven打包问题
2020-10-13 本文已影响0人
dhz120
在pom.xml中添加以下配置用于解决
- 依赖问题: Class Not Found Exception for a Maven Jar
- jar中没有主清单属性的问题
- Maven导出资源问题
<build>
<!--在build中配置resources,来防止我们资源导出失败的问题-->
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
<!-- 将依赖打入jar包中, 打包后会生成两个包,一个不带依赖,一个带依赖-->
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<!-- 此处为主入口, 需要改成自己的,如果不指定会报jar中没有主清单属性的问题-->
<mainClass>org.example.App</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>