使用过的两种maven打包方式:
第一种 jar包和依赖jar分离
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>${project.name}_lib/</classpathPrefix>
<mainClass>xxx.Start</mainClass>
</manifest>
</archive>
<excludes>
<exclude>test/</exclude>
</excludes>
<jarName>${project.name}</jarName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/${project.name}_lib
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
第二种 使用springboot打包方式,还在研究中
[table]
|<plugin>|
| <groupId>org.springframework.boot</groupId>|
| <artifactId>spring-boot-maven-plugin</artifactId>|
| <configuration>|
| <fork>true</fork>|
| <mainClass>xx.Start</mainClass>|
| </configuration>|
| <executions>|
| <execution>|
| <goals>|
| <goal>repackage</goal>|
| </goals>|
| </execution>|
| </executions>|
| </plugin>|
[/table]
打包前先 mvn clean mvn install 然后mvn package
--------------------------------------------------------------分享给迷茫的朋友
第一种 jar包和依赖jar分离
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>${project.name}_lib/</classpathPrefix>
<mainClass>xxx.Start</mainClass>
</manifest>
</archive>
<excludes>
<exclude>test/</exclude>
</excludes>
<jarName>${project.name}</jarName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/${project.name}_lib
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
第二种 使用springboot打包方式,还在研究中
[table]
|<plugin>|
| <groupId>org.springframework.boot</groupId>|
| <artifactId>spring-boot-maven-plugin</artifactId>|
| <configuration>|
| <fork>true</fork>|
| <mainClass>xx.Start</mainClass>|
| </configuration>|
| <executions>|
| <execution>|
| <goals>|
| <goal>repackage</goal>|
| </goals>|
| </execution>|
| </executions>|
| </plugin>|
[/table]
打包前先 mvn clean mvn install 然后mvn package
--------------------------------------------------------------分享给迷茫的朋友