maven打包插件


pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.6.RELEASE</version>
		<relativePath /> <!-- lookup parent from repository -->
	</parent>
	<groupId>com.hh.springboot.rocket</groupId>
	<artifactId>SpringBoot-Test</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<name>SpringBoot-Test</name>
 
 
	<properties>
		<java.version>1.8</java.version>
	</properties>
 
	<dependencies>
 
 
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
			<scope>runtime</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>fastjson</artifactId>
			<version>1.2.57</version>
		</dependency>
 
 
	</dependencies>
 
 
	<build>
		<!-- -->
		<finalName>${project.artifactId}</finalName>
		<plugins>
			<plugin>
				<!-- assembly插件 -->
				<artifactId>maven-assembly-plugin</artifactId>
				<configuration>
					<appendAssemblyId>false</appendAssemblyId>
					<finalName>${project.artifactId}</finalName>
					<archive>
						<manifest>
							<addClasspath>true</addClasspath>
							<mainClass>com.demo.IPPADemoApp</mainClass>
						</manifest>
					</archive>
					<descriptors>
						<descriptor>assembly.xml</descriptor>
					</descriptors>
				</configuration>
				<executions>
					<execution><!-- 配置执行器 -->
						<id>package</id>
						<phase>package</phase><!-- 绑定到package生命周期阶段上 -->
						<goals>
							<goal>single</goal><!-- 只运行一次 -->   
						</goals>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<configuration>
					<encoding>UTF-8</encoding>
					<useDefaultDelimiters>true</useDefaultDelimiters>
				</configuration>
			</plugin>
			
			<!-- java编译插件 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
					<encoding>UTF-8</encoding>
				</configuration>
			</plugin>
 
			<plugin>
				<!-- 拷贝依赖的jar包到lib目录 -->
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-dependency-plugin</artifactId>
				<executions>
					<execution>
						<id>copy</id>
						<phase>package</phase>
						<goals>
							<goal>copy-dependencies</goal>
						</goals>
						<configuration>
							<outputDirectory>
								${project.build.directory}/lib
							</outputDirectory>
						</configuration>
					</execution>
				</executions>
			</plugin>
 
		</plugins>
		
		<resources>
			
			<!-- 控制资源文件的拷贝 -->
			<resource>
				<directory>src/main/resources</directory>
				<targetPath>${project.build.directory}/conf</targetPath>
			</resource>
		</resources>
	</build>
 
 
</project>


assembly.xml

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
	<id>release</id>
	<includeBaseDirectory>true</includeBaseDirectory>
	
	<formats>
		<format>tar.gz</format>
		<format>dir</format>
	</formats>
	<fileSets>
		<fileSet>
			<outputDirectory>/bin</outputDirectory>
			<directory>${basedir}/profiles/${profile.id}/bin</directory>
		</fileSet>
		<fileSet>
			<outputDirectory>bin</outputDirectory>
			<directoryMode>0755</directoryMode>
			<directory>${basedir}/shell</directory>
		</fileSet>
		<fileSet>
			<outputDirectory>/conf</outputDirectory>
			<directory>${basedir}/profiles/${profile.id}/conf</directory>
		</fileSet>
		<fileSet>
			<outputDirectory>conf</outputDirectory>
			<directory>${basedir}/src/main/resources</directory>
		</fileSet>
	</fileSets>
	<dependencySets>
		<dependencySet>
			<scope>system</scope>
			<outputDirectory>lib</outputDirectory>
		</dependencySet>
		<dependencySet>
			<outputDirectory>lib</outputDirectory>
		</dependencySet>
	</dependencySets>
</assembly>


打包出来的结构:

项目名

———lib  (依赖包)

———conf (配置文件)

通常用作不带页面的后台服务。




maven 打包

2020.11.18 21:00

https://www.meihaocloud.com.com/213.html , 欢迎转载,请在文章页标出原文连接 !


Copyright © 2020 千夕网 联系站长

粤公网安备 44030302001408号 粤ICP备19099833号-1