Maven打包可執行jar並且壓縮
阿新 • • 發佈:2019-01-25
1. pom.xml
2. assembly.xml 編輯<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <!-- 在jar包中增加依賴jar路徑說明 --> <mainClass>com.zczy.generator.EntityGenerator</mainClass> </manifest> <!-- 用maven在MANIFEST.MF資料中的Class-Path中增加當前目錄(.) --> <manifestEntries> <Class-Path>.</Class-Path> </manifestEntries> </archive> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>2.2.1</version> <configuration> <appendAssemblyId>false</appendAssemblyId> <archive> <manifest> <mainClass>com.zczy.generator.EntityGenerator</mainClass> </manifest> </archive> <descriptors> <descriptor>assembly/assembly.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>assembly</goal> </goals> </execution> </executions> </plugin>
<assembly> <id>bin</id> <formats> <format>zip</format> </formats> <dependencySets> <dependencySet> <useProjectArtifact>true</useProjectArtifact> <outputDirectory>lib</outputDirectory> </dependencySet> </dependencySets> <fileSets> <fileSet> <outputDirectory>/</outputDirectory> <includes> <include>README.txt</include> </includes> </fileSet> <fileSet> <directory>/scripts</directory> <outputDirectory>/</outputDirectory> <includes> <include>gen.bat</include> </includes> </fileSet> <fileSet> <directory>/src/main/resources</directory> <outputDirectory>/</outputDirectory> <includes> <include>gen.properties</include> </includes> </fileSet> </fileSets> </assembly>