栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java > SpringBoot

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

SpringBoot 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

部署环境
  • window 10

  • redhat 6.4

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

POM.xml

    4.0.0

    com.elvish
    test
    0.0.1-SNAPSHOT
    jar

    test2
    test project for Spring Boot

    
        org.springframework.boot
        spring-boot-starter-parent
        1.5.10.RELEASE
        
    

    
        UTF-8
        UTF-8
        1.8
    

    
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.boot
            spring-boot-starter-thymeleaf
        
    

    
        test
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                
                    1.8
                    1.8
                
            
            
                org.apache.maven.plugins
                maven-dependency-plugin
                
                    
                        copy-dependencies
                        package
                        
                            copy-dependencies
                        
                        
                            target/lib
                            false
                            false
                            runtime
                        
                    
                
            
            
                org.springframework.boot
                spring-boot-maven-plugin
                
                    ZIP
                    
                        
                            cn.jstars
                            datatocloud
                        
                    
                
            
            
                org.apache.maven.plugins
                maven-resources-plugin
                
                    UTF-8
                
            
            
                org.apache.maven.plugins
                maven-surefire-plugin
                
                    true
                
            
        
        
            
                true
                src/main/resources
                
                    static/**
                    templates/**
                    *.yml
                    *.properties
                    *.xml
                    *.txt
                
            
        
    

解释说明

  • 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



作者:小红牛
链接:https://www.jianshu.com/p/7bf053450d39


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/234877.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号