• SpringBoot中打包设置,将配置文件打包在外部


    一.每次用maven的打包工具打包的时候 总是将配置文件一起打包进jar中!配置文件有点小修改就要重新打包很麻烦!!!!为了解决这一麻烦!找 了很多方法,下面的配置已经实现可用 

    我的项目目录结构如下

    1.pom.xml中的配置

    <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                                <classpathPrefix></classpathPrefix>
                                <mainClass>com.cn.Application</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <!-- The configuration of the plugin -->
                    <configuration>
                        <!-- Specifies the configuration file of the assembly plugin -->
                        <descriptors>
                            <descriptor>src/main/assembly/package.xml</descriptor>
                        </descriptors>
                    </configuration>
                    <executions>
                        <execution>
                            <id>make-assembly</id>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
            <resources>
                <resource>
                    <directory>src/main/java</directory>
                    <includes>
                        <include>**/*.xml</include>
                    </includes>
                    <filtering>false</filtering>
                </resource>
                <resource>
                    <directory>src/main/resources</directory>
                </resource>
                <resource>
                    <directory>lib/</directory>
                    <targetPath>lib</targetPath>
                    <includes>
                        <include>**/*.jar</include>
                    </includes>
                </resource>
            </resources>
    </build>

    在上面的配置中使用了一下两个工具

    maven-jar-plugin,负责将应用程序打包成可执行的jar文件 
    maven-assembly-plugin,负责将整个项目按照自定义的目录结构打成最终的压缩包,方便实际部署

    2.package.xml的配置如下

    <?xml version="1.0" encoding="UTF-8"?>
    <assembly
        xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
        <id>package</id>
        <formats>
            <format>zip</format>
        </formats>
        <includeBaseDirectory>true</includeBaseDirectory>
        <fileSets>
            <!-- 把项目相关的说明文件,打包进zip文件的根目录 -->
            <fileSet>
                <directory>${project.basedir}</directory>
                <outputDirectory>/</outputDirectory>
                <includes>
                    <include>README*</include>
                    <include>LICENSE*</include>
                    <include>NOTICE*</include>
                    <include>build.info</include>
                </includes>
            </fileSet>
    
            <fileSet>
                <directory>${project.basedir}/config</directory>
                <outputDirectory>config</outputDirectory>
                <includes>
                    <include>*.properties</include>
                    <include>ireport/*.jasper</include>
                </includes>
            </fileSet>
    
            <!-- 把项目自己编译出来的jar文件,打包进zip文件的根目录 -->
            <fileSet>
                <directory>${project.build.directory}</directory>
                <outputDirectory>/</outputDirectory>
                <includes>
                    <include>*.jar</include>
                </includes>
            </fileSet>
        </fileSets>
    </assembly>  
  • 相关阅读:
    spring boot下WebSocket消息推送(转)
    实时Web的发展历史
    mysqldump使用大全
    MYSQLDUMP参数详解(转)
    springboot页面缓存和url缓存实例
    在linux下运行jmeter
    jmeter测试http请求使用csv参数
    maven分开打包jar文件和依赖jar包和资源文件
    log4j DatePattern 解惑
    log4j使用示例
  • 原文地址:https://www.cnblogs.com/JoeyWong/p/9093444.html
Copyright © 2020-2023  润新知