Maven对Springboot项目配置文件、依赖分离打包

Springboot项目配置文件、依赖分离打包(一)

使用maven-assembly-plugin进行配置分离

assembly.xml配置文件



    
    
    ${name}

    
    
        tar.gz
        zip
    

    true

    
        
        
            src/main/resources/
            config
            0644
            
                application.yml
                *.xml
                *.properties
            
        
        
        
            ${basedir}/src/bin
            bin
            0755
            
                **.sh
                **.bat
            
        
    

    
        
            
            lib
            runtime
            0755
            
                ${project.groupId}:${project.artifactId}
            
        
        
            boot
            0755
            
                ${project.groupId}:${project.artifactId}
            
        
    

Pom.xml文件配置

pom文件中build属性的配置


    
    message
    
        
        
            org.springframework.boot
            spring-boot-maven-plugin
            
                ZIP
                
                    
                    
                        non-exists
                        non-exists
                    
                
            
        

        
        
            org.apache.maven.plugins
            maven-dependency-plugin
            3.1.0
            
                
                    prepare-package
                    
                        copy-dependencies
                    
                    
                        target/lib
                        false
                        false
                        true
                        compile
                    
                
            
        

        
        
            org.apache.maven.plugins
            maven-compiler-plugin
            
                
                ${java.version}
                ${java.version}
            
        

        
        
            org.apache.maven.plugins
            maven-surefire-plugin
            2.22.1
            
                true
            
        

        
        
            org.apache.maven.plugins
            maven-jar-plugin
            3.1.0
            
                
                    
                    
                    *.xml
                    *.properties
                    *.yml
                
                
                    
                        
                        xx.xxx.Application
                        
                        ../lib/
                        true
                    
                    
                    
                        ../config/
                    
                
            
        

        
        
            maven-assembly-plugin
            3.1.0
            
                
                    src/main/assembly/assembly.xml
                
            
            
                
                    make-assembly
                    package
                    
                        single
                    
                
            
        
    

运行

1.直接运行 java -jar xxxx.jar即可

2.编写shell/bash脚本

在bin目录下编写脚本文件如下:

shell

#! /bin/sh

HOME = '/opt/xxx/boot'
JAR_HOME = 'xxx.jar'

cd $HOME
nohup java -jar $JAR_HOME

bash

@echo off
rem ======================================================================
rem windows startup script
rem
rem ======================================================================
rem startup jar

java -jar ../boot/xxx.jar

pause

项目目录如下

关注我的微信公众账号,分享更多~

你可能感兴趣的:(assembly,java,springboot,maven)