该方法只可打包非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
如果这个不管用,可以参考https://www.jb51.net/article/276771.htm
到此这篇关于Maven 项目用Assembly打包可执行jar包的方法的文章就介绍到这了,更多相关Maven打包可执行jar包内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!