利用maven将springboot的配置文件打到jar包外面


1. 为了部署时更加方便,将spring项目的配置文件和依赖jar包打到外面,方便修改.使用maven插件进行打包,打包完后压缩成zip,方便传输.首先配置项目maven,添加两个插件.


        app
        
            
            
            org.apache.maven.plugins
            maven-jar-plugin
            
                
                    
                        true
                        lib
                        
                        com.lp.Application
                    
                    
                        ./
                    
                
                
                    
                    *.properties
                    *.xml
                    *.bat
                
            
        
            
                org.apache.maven.plugins
                maven-assembly-plugin
                
                    
                        make-zip
                        package
                        
                            single
                        
                        
                            
                            false
                            
                                
                                src/main/resources/assembly.xml
                            
                        
                    
                
            
        

2. 接下来在resources目录下新建一个assembly.xml,里面设置打包的具体策略

<?xml version="1.0" encoding="UTF-8"?>

    package
    
        zip
    
    
    false
    
        
            bin
            ${file.separator}
        
        
            src/main/resources
            ${file.separator}
            
            
                static/**
                templates/**
                application.yml
            
            
            
                application-database.properties
                assembly.xml
                logback-spring.xml
                run.bat
            
        
        
            ${project.build.directory}
            ${file.separator}
            
                *.jar
            
        
    
    
        
            lib
            runtime
            
                ${groupId}:${artifactId}
            
        
    

3. run.bat中的内容是运行jar的命令,方便解压后双击运行.

@echo off
java -jar app.jar
pause