Springboot 打jar包分离lib,配置文件正确方式(二)

背景

从《Springboot 打jar包分离lib,配置文件正确方式》中,可以达到把配置文件和依赖第三方的jar包分离开,但稍显有点臃肿,今天再次提供一种方式,供大家参考。

部署环境

  • window 10
  • redhat 6.4
  • 其他版本没有尝试,应该也是可以的

POM.xml

<?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>test2</name>
<description>test project for Spring Boot</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>
<finalName>test</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</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>target/lib</outputDirectory>
<excludeTransitive>false</excludeTransitive>
<stripVersion>false</stripVersion>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layout>ZIP</layout>
<includes>
<include>
<groupId>cn.jstars</groupId>
<artifactId>datatocloud</artifactId>
</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
<excludes>
<exclude>static/**</exclude>
<exclude>templates/**</exclude>
<exclude>*.yml</exclude>
<exclude>*.properties</exclude>
<exclude>*.xml</exclude>
<exclude>*.txt</exclude>
</excludes>
</resource>
</resources>
</build> </project>

解释说明

  • maven-dependency-plugin 打出项目依赖的第三方包,放在lib下面
  • spring-boot-maven-plugin springboot打包插件,只保留了项目运行的jar包
  • resources 排除了我们需要外置的文件

运行方式

将target下lib包和test.jar(运行包)以及src/main/resources下你需要外置的文件部署至服务器同一目录下,如

  • lib
  • test.jar
  • *.yml
  • *.xml
  • *.properties
  • static
  • templates

最终运行

java -jar -Dloader.path=.,lib test.jar

Springboot 打jar包分离lib,配置文件正确方式(二)的更多相关文章

  1. Springboot 打jar包分离lib,配置文件正确方式

    文章来源:https://my.oschina.net/xiaozhutefannao/blog/1932764 POM.xml <?xml version="1.0" en ...

  2. springboot打jar包,调用webservice出错

    错误提示 Caused by: java.lang.ClassNotFoundException: com/sun/tools/internal/xjc/api/XJC 在idea中没有问题,但是打成 ...

  3. springboot打成jar包和war包的两种方式,并引入第三方jar包!

    springboot打成jar包和war包的两种方式,并引入第三方jar包! 首先把需要引入的第三方jar包引入到本地项目中,在引用的模块下加一个lib文件夹 一.打成jar包 1.修改pom文件里的 ...

  4. main函数读取jar包外部的配置文件properties

    首先,Java的main方法有个初始化入参args,如下所示: public static void main(String[] args) {} 然后,在linux下执行jar包引入外部配置文件的命 ...

  5. 更新jar包里的配置文件

    更新jar包里的配置文件 起因 从笔记本传了个jar到服务器,运行的时候才发现配置文件一个ip项填错了.本来很简单的问题,maven重新打包就可以了,但是30多M的jar包就因为一个配置项错了又要重新 ...

  6. SpringBoot打jar包问题

    原文:https://jingyan.baidu.com/article/6f2f55a11d6e09b5b93e6c9e.html 当你使用springBoot进行打包的时候,这篇经验会帮助到你的. ...

  7. springboot以jar包方式启动、关闭、重启脚本

    springboot以jar包方式启动.关闭.重启脚本 启动 编写启动脚本startup.sh #!/bin/bash echo Starting application nohup java -ja ...

  8. Maven引入jar包中的配置文件未被识别

    我用的办法是直接将jar包中的配置文件复制出来,粘贴到我自己项目中的配置文件中,讯飞语音的jar包就有这种情况.

  9. springboot项目jar包运行

    springboot项目jar包运行 参考 Linux后台运行java的jar包 步骤 进入maven项目中,打包项目. mvn package -Dmaven.test.skip=true 运行ja ...

随机推荐

  1. =default(c++11)

    1.概念 1)如果我们需要编译器默认的行为,则可以在参数列表后面加上=default来显式地要求编译器生成合成版本的默认构造函数和拷贝控制成员:合成的默认构造函数.合成拷贝构造函数.合成拷贝赋值运算符 ...

  2. Excel获得焦点变色

    1.  点击 Sheet 2. 右键菜单  查看代码 3. 复制如下代码 Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Ran ...

  3. [翻译]Spring MVC RESTFul Web Service CRUD 例子

    Spring MVC RESTFul Web Service CRUD 例子 本文主要翻译自:http://memorynotfound.com/spring-mvc-restful-web-serv ...

  4. hdu 5015 233矩阵快速幂

    http://acm.hdu.edu.cn/showproblem.php?pid=5015 需要构造一个 n+2 维的矩阵. 就是要增加一维去维护2333这样的序列. 可以发现 2333 = 233 ...

  5. [leetcode] 14. Climbing Stairs

    这道题leetcode上面写着是DP问题,问题是我一开始写了个简单的递归结果直接超时,所以没办法只好拿迭代来做了.题目如下: You are climbing a stair case. It tak ...

  6. const 用法全面总结

    C++中的const关键字的用法非常灵活,而使用const将大大改善程序的健壮性,本人根据各方面查到的资料进行总结如下,期望对朋友们有所帮助. Const 是C++中常用的类型修饰符,常类型是指使用类 ...

  7. Windows下VM安装MacOS

    我们在使用Windows操作系统的情况下,不去买苹果电脑,想去玩玩Mac苹果操作系统,有两种选择,一种就是安装黑苹果(就是在非苹果电脑上安装MacOS)这种方式不推荐,因为你会遇到很多很多不兼容问题, ...

  8. ModuleNotFoundError: No module named 'sqlite'

    解决 ModuleNotFoundError: No module named 'sqlite'.问题 今天在将Python2.7升级至Python3.6后导入sqlite模块时出现了一下报错,到网上 ...

  9. apache模块 合并多个js/css 提高网页加载速度

    win :  http://blog.csdn.net/mycwq/article/details/9361117 linux :http://blog.csdn.net/mycwq/article/ ...

  10. unlimited channel buffer in Go

    channel buffer可以事先分配大小,但是这些是需要占用内存的,事先分配几G内存给一个channel很浪费资源的,所以怎样创建一个无限的channel buffer呢?比较naive的写法就是 ...