zoukankan      html  css  js  c++  java
  • spring/boot 打包,资源/配置/业务文件分离

    spring/boot 打包,资源/配置/业务文件分离

    spring/boot打包,将业务jar包和资源配置文件进行分离打包,打包后的资源在target/release文件夹下面

    注意:添加以下配置后,注意修改自己的入口类

    <!--相关编译打包依赖-->
        <build>
            <plugins>
                <!--打包jar-->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>
                        <!--不打包资源文件-->
                        <excludes>
                            <exclude>*.**</exclude>
                            <exclude>*/*.xml</exclude>
                            <exclude>*/*.html</exclude>
                            <exclude>*/*.yml</exclude>
                        </excludes>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                                <!--MANIFEST.MF 中 Class-Path 加入前缀-->
                                <classpathPrefix>lib/</classpathPrefix>
                                <!--jar包不包含唯一版本标识-->
                                <useUniqueVersions>false</useUniqueVersions>
                                <!--指定入口类,修改成自己项目的入口类 -->
                                <mainClass>com.github.example.ExampleApplication</mainClass>
                            </manifest>
                            <manifestEntries>
                                <!--MANIFEST.MF 中 Class-Path 加入资源文件目录-->
                                <Class-Path>./resources/</Class-Path>
                            </manifestEntries>
                        </archive>
                        <outputDirectory>${project.build.directory}/release</outputDirectory>
                    </configuration>
                </plugin>
    
                <!--拷贝第三方依赖文件到指定目录-->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>copy-dependencies</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>
                                    ${project.build.directory}/release/lib/
                                </outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
    
                <!--拷贝资源文件 copy-resources-->
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>copy-resources</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-resources</goal>
                            </goals>
                            <configuration>
                                <resources>
                                    <resource>
                                        <directory>src/main/resources</directory>
                                    </resource>
                                </resources>
                                <outputDirectory>${project.build.directory}/release/resources</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
    
                <!--spring boot repackage,依赖 maven-jar-plugin 打包的jar包 重新打包成 spring boot 的jar包-->
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <!--重写包含依赖,包含不存在的依赖,jar里没有pom里的依赖-->
                        <includes>
                            <include>
                                <groupId>null</groupId>
                                <artifactId>null</artifactId>
                            </include>
                        </includes>
                        <layout>ZIP</layout>
                        <!--使用外部配置文件,jar包里没有资源文件-->
                        <addResources>true</addResources>
                        <outputDirectory>${project.build.directory}/release</outputDirectory>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>repackage</goal>
                            </goals>
                            <configuration>
                                <!--配置jar包特殊标识 配置后,保留原文件,生成新文件 *-run.jar -->
                                <!--配置jar包特殊标识 不配置,原文件命名为 *.jar.original,生成新文件 *.jar -->
                                <!--<classifier>run</classifier>-->
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
    
            </plugins>
        </build>
    
  • 相关阅读:
    Oracle根据【日期】组,其他条件根据PIVOT行转列。使每个日期条件关联的其他数据只有一行。
    ORACLE数据库,数据量大,转移数据到备份表语句
    C#解析"a=1&b=2&c=3"字符串,微信支付返回字符串,替换<br>为&
    dataTable的数据,调试的时候点放大镜就看到了啊啊啊!
    Debug和Release 老程序啊 调试之前 区分一下啊
    FastReport.NET
    grpc 实现微服务生态笔记
    金木水火土
    shell 指令分析nginx 日志qps
    idea中使用tomcat 方式启动spring boot项目
  • 原文地址:https://www.cnblogs.com/YangGC/p/12191566.html
Copyright © 2011-2022 走看看