java

关注公众号 jb51net

关闭
首页 > 软件编程 > java > SpringBoot生产环境打包去除无用依赖

SpringBoot生产环境打包如何去除无用依赖

作者:松鸟

这篇文章主要介绍了SpringBoot生产环境打包如何去除无用依赖问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教

SpringBoot生产环境打包去除无用依赖

去除在生产环境中不变的依赖第三方jar包

pom.xml中添加:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <layout>ZIP</layout>
        <!--去除在生产环境中不变的依赖-->
        <excludeGroupIds>
            org.springframework.boot,
            org.springframework,
            org.springframework.data,
            com.fasterxml.jackson.core,
            com.fasterxml.jackson.databind,
            org.apache.commons,
            org.apache.tomcat.embed,
            org.hibernate.validator,
            org.slf4j,
            com.jayway,
            org.jboss,
            com.alibaba,
            com.fasterxml,
            com.fasterxml.jackson.datatype,
            com.fasterxml.jackson.module,
            ch.qos.logback,
            org.yaml,
            org.jboss.logging,
            javax.validation,
            io.netty,
            org.apache.httpcomponents,
            org.apache.logging.log4j,
            org.aspectj,
            javax.annotation,
            io.lettuce,
            commons-codec,
            org.reactivestreams,
            io.projectreactor
        </excludeGroupIds>
    </configuration>
</plugin>

去除生产环境配置文件依赖

pom.xml中添加:

<resources>
    <resource>
        <directory>src/main/resources</directory>
        <excludes>
            <exclude>*</exclude>
        </excludes>
        <filtering>true</filtering>
    </resource>
</resources>

Springboot生产环境打包成jar

<build>
        <sourceDirectory>src/main/java</sourceDirectory>
        <plugins>
            <!-- 打包插件 -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- 解决本地jar植入的插件 -->
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <encoding>UTF-8</encoding>
                    <compilerArguments>
                        <extdirs>src\main\webapp\WEB-INF\lib</extdirs>
                    </compilerArguments>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <packaging>jar</packaging>

通过上述pom.xml文件完成打包前的配置工作

在终端中切换到工程目录运行:mvn clean package生成打包后的文件,java -jar 运行jar包 即可

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文