• 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>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36

    启动打包的jar文件

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

    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>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
  • 相关阅读:
    制作一个简单HTML电影网页设计(HTML+CSS)
    动态规划问题——LIS相关
    VSCode使用简介
    nodejs毕业设计学生宿舍寝室管理系统
    子选择器(重点)
    神经网络卷积层
    [附源码]SSM计算机毕业设计中青年健康管理监测系统JAVA
    QT汽车客运公司售票系统(改良版)
    Vant4 List列表组件:资源中有项目合集案列
    基于粒子群算法优化BP神经网络的PID控制算法(Matlab代码实现)
  • 原文地址:https://blog.csdn.net/admin_web/article/details/132687284