这篇文章主要介绍“Maven项目如何用Assembly打包可执行jar包”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“Maven项目如何用Assembly打包可执行jar包”文章能帮助大家解决问题。
该方法只可打包非spring项目的可执行jar包
1、添加maven插件
<build>
<finalName>DataCollector</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<!-- 设置源文件编码方式 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!--mvn assembly:assembly命令打jar包-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.main.RunMain</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
2、mvn clean(清理下项目)
3、maven update project(用eclipse工具)
4、命令后执行命令mvn assembly:assembly -Dmaven.test.skip
进入target目录会看到这jar包:DataCollector.jar
5、执行 java -jar DataCollector.jar