一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|JavaScript|易語言|

服務(wù)器之家 - 編程語言 - JAVA教程 - Spring boot 打jar包分離lib的正確配置方式

Spring boot 打jar包分離lib的正確配置方式

2021-04-07 13:33小祝特?zé)?/span> JAVA教程

spring boot打jar包分離lib后,配置文件的方式,在網(wǎng)上可以搜到很多答案,但是都不夠完善,今天小編給大家?guī)砹薙pring boot 打jar包分離lib的正確配置方式,感興趣的朋友一起看看吧

前言

Springboot 打jar包分離lib,配置文件的方式,網(wǎng)上可以搜到的我都沒試通。跟劉大神(大神沒有博客,很可惜)討論后,給出了這么一個(gè)解決方案,供大家參考。

部署環(huán)境

  • window 10
  • redhat 6.4
  • 其他版本沒有嘗試,應(yīng)該也是可以的

POM.xml

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.elvish</groupId>
  <artifactId>test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>test</name>
  <description>test</description>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.10.RELEASE</version>
    <relativePath />
  </parent>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <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>target/lib</outputDirectory>
              <excludeTransitive>false</excludeTransitive>
              <stripVersion>false</stripVersion>
              <includeScope>runtime</includeScope>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
          <excludes>
            <exclude>**/*.properties</exclude>
            <exclude>**/*.xml</exclude>
            <exclude>**/*.yml</exclude>
            <exclude>static/**</exclude>
            <exclude>templates/**</exclude>
          </excludes>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
          <layout>ZIP</layout>
          <includes>
            <include>
              <groupId>non-exists</groupId>
              <artifactId>non-exists</artifactId>
            </include>
          </includes>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>repackage</goal>
            </goals>
            <configuration>
              <classifier>classes</classifier>
              <attach>false</attach>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
                <property name="dist">target/distribution</property>
                <property name="dist-tmp">target/distribution/tmp</property>
                <property name="app-name">${project.artifactId}-${project.version}</property>
                <mkdir dir="${dist-tmp}" />
                <copy file="target/${app-name}.jar" tofile="${dist-tmp}/${app-name}.jar" />
                <unzip src="${dist-tmp}/${app-name}.jar" dest="${dist-tmp}" />
                <delete file="${dist-tmp}/${app-name}.jar" />
                <zip destfile="${dist}/${app-name}-pages.jar">
                  <zipfileset dir="${dist-tmp}/META-INF" prefix="META-INF" />
                  <zipfileset dir="target/classes/static" prefix="static" />
                  <zipfileset dir="target/classes/templates" prefix="templates" />
                </zip>
                <move file="target/${app-name}-classes.jar" todir="${dist}" />
                <move todir="${dist}/3rd-lib">
                  <fileset dir="target/lib" />
                </move>
                <delete dir="${dist-tmp}" />
                <copy todir="${dist}">
                  <fileset dir="target/classes">
                    <include name="**/*.properties" />
                    <include name="**/*.xml" />
                    <include name="**/*.yml" />
                  </fileset>
                </copy>
              </target>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

打完包后目錄結(jié)構(gòu)

  • 3rd-lib
  • META-INF
  • *.yml
  • *.xml
  • *.properties
  • test-0.0.1-SNAPSHOT-classes.jar
  • test-0.0.1-SNAPSHOT-pages.jar

運(yùn)行jar

?
1
java -jar -Dloader.path=.,3rd-lib test-0.0.1-SNAPSHOT-classes.jar

總結(jié)

以上所述是小編給大家介紹的Spring boot 打jar包分離lib的正確配置方式,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對服務(wù)器之家網(wǎng)站的支持!

原文鏈接:https://my.oschina.net/xiaozhutefannao/blog/1624092

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产成人手机在线 | 精品国产精品人妻久久无码五月天 | 动漫美女人物被黄漫在线看 | 成人免费国产欧美日韩你懂的 | hd性欧美俱乐部中文 | 美女奶口隐私免费视频网站 | 国产首页精品 | 免费看黄色一级 | 国产精品免费看香蕉 | 国产91免费在线 | 亚洲品质自拍视频 | 二区三区不卡不卡视频 | 91制片厂果冻星空传媒3xg | 亚洲第五色综合网啪啪 | 青青草原影院 | 亚洲大片在线观看 | 手机看片自拍 | 国产日韩一区二区三区在线播放 | 免费理伦片高清在线 | 久久国产加勒比精品无码 | 小鸟酱喷水 | 日日插插 | 久久伊人影视 | 美女的隐私脱裤子无遮挡 | 日b在线观看| 俄罗斯一级在线播放 | 久久成人精品免费播放 | 日本嫩小xxxxhd| 国产一级毛片潘金莲的奶头 | 午夜特级毛片 | 草莓丝瓜芭乐樱桃榴莲色多黄 | 91精品国产品国语在线不卡 | 91丝袜足控免费网站xx | 91xj视频| 国产人成精品午夜在线观看 | 日本大片免aaa费观看视频 | 9久re热视频这里只有精品 | 91理论片午午伦夜理片久久 | 91精品综合久久久久m3u8 | 色呦呦在线免费观看 | 9久热久爱免费精品视频在线观看 |