Maven 專案用Assembly打包可執行jar包
阿新 • • 發佈:2022-05-06
該方法只可打包非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
如果這個不管用,可以參考http://www.cnblogs.com/liqiu/p/3816068.html
————————————————
版權宣告:本文為CSDN博主「張志翔 ̮」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處連結及本宣告。
原文連結:https://blog.csdn.net/qq_19734597/article/details/121295730