Springboot瘦身打包

准备

  • springboot 版本 2.3.9.RELEASE
  • maven

assembly.xml 配置

我这边放在resources下面

<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>binid>
    
    <formats>
        <format>dirformat>
    formats>
    
    <includeBaseDirectory>falseincludeBaseDirectory>
    <dependencySets>
        <dependencySet>
            
            <useProjectArtifact>falseuseProjectArtifact>
            <outputDirectory>liboutputDirectory>
            <unpack>falseunpack>
        dependencySet>
    dependencySets>
    <fileSets>
        
        <fileSet>
            <directory>${project.basedir}directory>
            <outputDirectory>outputDirectory>
            <includes>
                <include>README*include>
                <include>LICENSE*include>
                <include>NOTICE*include>
            includes>
        fileSet>
        
        <fileSet>
            <directory>${project.basedir}/src/main/resourcesdirectory>
            <outputDirectory>configoutputDirectory>
        fileSet>
        
        <fileSet>
            <directory>${project.basedir}/src/main/bindirectory>
            <outputDirectory>binoutputDirectory>
        fileSet>
        
        <fileSet>
            <directory>${project.build.directory}directory>
            <outputDirectory>outputDirectory>
            <includes>
                <include>*.jarinclude>
            includes>
        fileSet>
    fileSets>
assembly>

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>2.3.9.RELEASEversion>
        <relativePath/> 
    parent>
    <groupId>com.freyagroupId>
    <artifactId>project-thinartifactId>
    <version>0.0.1-SNAPSHOTversion>
    <name>project-thinname>
    <description>project-thindescription>
    <properties>
        <java.version>1.8java.version>
    properties>
    <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>
    dependencies>

    <build>
        <plugins>
            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-jar-pluginartifactId>
                <configuration>
                    <archive>
                        
                        <addMavenDescriptor>falseaddMavenDescriptor>
                        <manifest>
                            
                            <addClasspath>trueaddClasspath>
                            
                            <classpathPrefix>lib/classpathPrefix>
                            
                            <mainClass>com.freya.projectthin.ProjectThinApplicationmainClass>
                        manifest>
                    archive>
                configuration>
            plugin>
            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-assembly-pluginartifactId>
                <configuration>
                    <descriptors>
                        
                        <descriptor>src/main/resources/assembly.xmldescriptor>
                    descriptors>
                configuration>
                <executions>
                    <execution>
                        <id>make-assemblyid>
                        <phase>packagephase>
                        <goals>
                            <goal>singlegoal>
                        goals>
                    execution>
                executions>
            plugin>
            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-surefire-pluginartifactId>
                <configuration>
                    <skipTests>trueskipTests>
                configuration>
            plugin>
        plugins>
    build>

project>

效果

Springboot瘦身打包_第1张图片

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