pom
<build>
<plugins>
<!-- 设定JDK版本 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<showWarnings>true</showWarnings>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
<!--打成jar包;指定main入口方法;排除配置文件;-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<!--MANIFEST.MF Class-Path 加入前缀-->
<classpathPrefix>lib/</classpathPrefix>
<!--jar包不包含唯一版本标识-->
<useUniqueVersions>false</useUniqueVersions>
<!--指定入口-->
<mainClass>com.sinovatio.owls.kapp.KApp</mainClass>
</manifest>
<manifestEntries>
<!--MANIFEST.MF 中 Class-Path 加入资源文件目录-->
<Class-Path>./config/</Class-Path>
</manifestEntries>
</archive>
<excludes>
<exclude>**/*.yml</exclude>
<exclude>**/*.properties</exclude>
<exclude>**/*.yaml</exclude>
<exclude>**/logback-core.xml</exclude>
</excludes>
</configuration>
</plugin>
<!--上面第三方包路径加了lib,下面拷贝第三方包到lib-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/lib/
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!--assembly: 整理所有资源,打成压缩包-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<!--最终包名-->
<finalName>${project.artifactId}-${project.version}</finalName>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
<!--绑定包maven生命周期,直接用maven packge打包-->
<executions>
<execution>
<id>make-assembly-tar</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<!--下面的文件不会放入jar包,但是会放在target/classes/这里-->
<!--后面在assembly.xml配置文件中,再将classes下面这些文件放在合适位置-->
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/**</include>
<include>**</include>
</includes>
</resource>
<resource>
<directory>bin</directory>
<includes>
<include>**/**</include>
<include>**</include>
</includes>
<targetPath>bin</targetPath>
</resource>
<resource>
<directory>devops</directory>
<includes>
<include>**/**</include>
<include>**</include>
</includes>
<targetPath>devops</targetPath>
</resource>
</resources>
</build>
pom说明
maven-jar-plugin的作用:
* 将项目打成jar包
* 指定项目的main方法为项目入口
* 将项目的配置文件脱离jar包,并加上前径,如config/
* 将项目的依赖包脱离jar包,并加上路径,如lib/
maven-dependency-plugin的作用:
* 将项目依赖的jar包,放入lib/下面(这里需要和上面一致)
maven-assembly-plugin的作用:
* 将项目所有资源,打成一个压缩包,如xxx.tar.gz(其实就是归整target目录下的资源)
assembly.xml
注意:assembly.xml文件位置和pom.xml一致,是在项目的根目录下。
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0";
xmlns:xsi="http://www.w3.org/2001/xmlschema-instance";
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">;
<id>release</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<fileSets>
<!--*.properties,*.yml配置文件输出到config目录-->
<fileSet>
<directory>${project.build.directory}/classes</directory>
<outputDirectory>config</outputDirectory>
<includes>
<include>**.properties</include>
<include>**.yaml</include>
<include>**.yml</include>
<include>**.xml</include>
</includes>
</fileSet>
<!--依赖包输出到lib目录-->
<fileSet>
<directory>${project.build.directory}/lib</directory>
<outputDirectory>lib</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<!--启动脚本输出到bin目录-->
<fileSet>
<directory>${project.build.directory}/classes/bin</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>**.sh</include>
</includes>
</fileSet>
<!-- 把项目自己编译出来的jar文件,打包进zip文件的根目录 -->
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>
标签:xml,project,SpringBoot,lib,plugin,jar,maven
From: https://www.cnblogs.com/zhujinchong/p/17435705.html