码迷,mamicode.com
首页 > 编程语言 > 详细

spring boot项目将配置文件打包在外部

时间:2020-04-26 19:06:09      阅读:68      评论:0      收藏:0      [点我收藏+]

标签:tput   conf   lap   mic   esc   xmlns   isp   boot   cti   

一、打成jar包不应该包含配置文件

技术图片

 

二、添加打成压缩包的插件,配置插件中添加项目的配置文件

技术图片

技术图片

 

 

参考文件

1.pom.xml

技术图片
 1 <build>
 2         <!-- 产生的构件的文件名,默认值是${artifactId}-${version}。 -->
 3         <finalName>${artifactId}</finalName>
 4         <plugins>
 5             <plugin>
 6                 <groupId>org.springframework.boot</groupId>
 7                 <artifactId>spring-boot-maven-plugin</artifactId>
 8                 <executions>
 9                     <execution>
10                         <goals>
11                             <goal>repackage</goal>
12                         </goals>
13                     </execution>
14                 </executions>
15                 <configuration>
16                     <includeSystemScope>true</includeSystemScope>
17                 </configuration>
18             </plugin>
19             <plugin>
20                 <groupId>org.apache.maven.plugins</groupId>
21                 <artifactId>maven-assembly-plugin</artifactId>
22                 <configuration>
23                     <descriptors>
24                         <descriptor>src/main/assembly/package.xml</descriptor>
25                     </descriptors>
26                 </configuration>
27                 <executions>
28                     <execution>
29                         <id>make-assembly</id>
30                         <phase>package</phase>
31                         <goals>
32                             <goal>single</goal>
33                         </goals>
34                     </execution>
35                 </executions>
36             </plugin>
37         </plugins>
38         <resources>
39             <resource>
40                 <directory>src/main/java</directory>
41                 <includes>
42                     <include>**/*.xml</include>
43                 </includes>
44                 <filtering>true</filtering>
45             </resource>
46             <resource>
47                 <directory>src/main/resources</directory>
48                 <excludes>
49                     <exclude>**/*.properties</exclude>
50                     <exclude>**/*.yml</exclude>
51                 </excludes>
52                 <filtering>false</filtering>
53             </resource>
54             <resource>
55                 <directory>lib/</directory>
56                 <targetPath>lib</targetPath>
57                 <includes>
58                     <include>**/*.jar</include>
59                 </includes>
60             </resource>
61         </resources>
62     </build>
View Code

 

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}/src/main/resources</directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>*.properties</include>
            </includes>
        </fileSet>

        <!-- 把项目自己编译出来的jar文件,打包进zip文件的根目录 -->
        <fileSet>
            <directory>${project.build.directory}</directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>
View Code

 

spring boot项目将配置文件打包在外部

标签:tput   conf   lap   mic   esc   xmlns   isp   boot   cti   

原文地址:https://www.cnblogs.com/z-test/p/12781384.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!