springboot项目打包优化,将所有第三方包单独打包至lib目录

在pom.xml中配置以下代码,随后使用mvnw clean package打包

<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.bootgroupId>
				<artifactId>spring-boot-maven-pluginartifactId>
				<configuration>
					
					<mainClass>com.server.ServerDemoApplicationmainClass>
                    <executable>trueexecutable>
                    <layout>ZIPlayout>
                    <includes>
                        <include>
                            <groupId>nothinggroupId>
                            <artifactId>nothingartifactId>
                        include>
                    includes>
                configuration>
			plugin>
			
			<plugin>
				<groupId>org.apache.maven.pluginsgroupId>
				<artifactId>maven-dependency-pluginartifactId>
				<executions>
					<execution>
						<id>copy-dependenciesid>
						<phase>packagephase>
						<goals>
							<goal>copy-dependenciesgoal>
						goals>
						<configuration><outputDirectory>${project.build.directory}/liboutputDirectory>
						configuration>
					execution>
				executions>
			plugin>
		plugins>
	build>

启动打包的jar文件

java -Dloader.path=./lib -jar xxx.jar

pom.xml(完整代码)


<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0modelVersion>
	<parent>
		<groupId>org.springframework.bootgroupId>
		<artifactId>spring-boot-starter-parentartifactId>
		<version>3.1.1version>
		<relativePath/> 
	parent>
	<groupId>com.servergroupId>
	<artifactId>server_nameartifactId>
	<version>0.0.1-SNAPSHOTversion>
	<name>server_namename>
	<description>Demo project for Spring Bootdescription>
	<properties>
		<java.version>17java.version>
	properties>
	<repositories>
		<repository>
			<id>alimavenid>
			<name>aliyun mavenname>
			<layout>defaultlayout>
			<url>http://maven.aliyun.com/nexus/content/groups/public/url>
		repository>
	repositories>

	<pluginRepositories>
		<pluginRepository>
			<id>alimavenid>
			<url>http://maven.aliyun.com/nexus/content/groups/public/url>
		pluginRepository>
	pluginRepositories>
	<dependencies>
		<dependency>
			<groupId>org.springframework.bootgroupId>
			<artifactId>spring-boot-starter-webartifactId>
		dependency>

		<dependency>
			<groupId>org.springframework.bootgroupId>
			<artifactId>spring-boot-starter-testartifactId>
			<scope>testscope>
		dependency>
		<dependency>
			<groupId>com.github.pengglegroupId>
			<artifactId>kaptchaartifactId>
			<version>2.3.2version>
		dependency>
		<dependency>
			<groupId>com.alibaba.fastjson2groupId>
			<artifactId>fastjson2artifactId>
			<version>2.0.32version>
		dependency>
		<dependency>
			<groupId>com.baomidougroupId>
			<artifactId>mybatis-plus-boot-starterartifactId>
			<version>3.5.3version>
		dependency>
		<dependency>
			<groupId>com.mysqlgroupId>
			<artifactId>mysql-connector-jartifactId>
			<scope>runtimescope>
		dependency>
		<dependency>
			<groupId>com.alibabagroupId>
			<artifactId>easyexcelartifactId>
			<version>3.3.2version>
		dependency>
	dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.bootgroupId>
				<artifactId>spring-boot-maven-pluginartifactId>
				<configuration>
					
					<mainClass>com.server.ServerDemoApplicationmainClass>
                    <executable>trueexecutable>
                    <layout>ZIPlayout>
                    <includes>
                        <include>
                            <groupId>nothinggroupId>
                            <artifactId>nothingartifactId>
                        include>
                    includes>
                configuration>
			plugin>
			
			<plugin>
				<groupId>org.apache.maven.pluginsgroupId>
				<artifactId>maven-dependency-pluginartifactId>
				<executions>
					<execution>
						<id>copy-dependenciesid>
						<phase>packagephase>
						<goals>
							<goal>copy-dependenciesgoal>
						goals>
						<configuration><outputDirectory>${project.build.directory}/liboutputDirectory>
						configuration>
					execution>
				executions>
			plugin>
		plugins>
	build>

project>

你可能感兴趣的:(java,spring,boot,后端,java)