Maven 项目用Assembly打包可执行jar包的方法
幸福眼泪 人气:0该方法只可打包非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:
加载全部内容