项目场景:
对完成的java项目使用maven进行打包,并打包成可运行jar文件。
问题描述:
mvn clean compile
mvn clean package
java -jar xxx.jar
运行jar包时出现没有
- -SNAPSHOT.jar中没有主清单属性
- resource文件夹的包没有导入
解决方法需要对项目中的配置文件进行改动。
解决方案:
主清单属性是指可运行jar包中的main函数,如果要运行jar包需要指明一个运行的入口,需要改动pom.xml。
添加:
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.noteligible.pojo.main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
其中mainClass指的是main函数的函数位置。
maven似乎默认不打包resource文件夹中的jar包,需要再pom.xml中添加:
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</resource>
directory>指明了需要打包的目录路径。