SpringBoot打包 lib分离 config分离

最终打包后的目录结构

│   start.sh
├───config
│       application-dev.yml
│       application-prod.yml
│       application.yml
│       ehcache.xml
│       logback.xml
├───logs
├───lib
│       spring-context-support-5.1.2.RELEASE.jar
│       spring-core-5.1.2.RELEASE.jar
│       spring-oxm-5.1.2.RELEASE.jar
│       spring-retry-1.2.2.RELEASE.jar
│       spring-tx-5.1.2.RELEASE.jar
│       stax2-api-3.1.4.jar
│       woodstox-core-5.0.3.jar
│       zkclient-0.10.jar
│       zookeeper-3.4.11.jar
│ 		 .........
└───logs

pom.xml


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

            
            
                org.apache.maven.plugins
                maven-resources-plugin
                2.7
                
                    UTF-8
                
            
            
                org.apache.maven.plugins
                maven-jar-plugin
                
                    
                        **/*.properties
                        **/*.xml
                        **/*.yml
                        static/**
                        templates/**
                    
                
            
            
                org.apache.maven.plugins
                maven-surefire-plugin
                2.18.1
                
                    true
                
            
            
                org.springframework.boot
                spring-boot-maven-plugin
                
                    ZIP
                    
                        
                            cn.wisec.meerkat
                            meerkat-slice
                        
                    
                
            
            
                org.apache.maven.plugins
                maven-dependency-plugin
                
                    
                        copy-dependencies
                        package
                        
                            copy-dependencies
                        
                        
                            target/lib
                            false
                            false
                            runtime
                        
                    
                
            
            
                org.apache.maven.plugins
                maven-assembly-plugin
                2.5.3
                  
                    
                        make-zip
                        package
                        
                            single
                        
                        
                             
                                src/main/bin/assembly.xml
                            
                        
                    
                
            

        
    

src/main/bin/assembly.xml


    bin
    
        zip
    
    
        
            src/main/resources
            /config/
            
                **/*
            
        
        
            ${project.build.directory}
            /
            
                lib/*.jar
            
        
        
            ${project.build.directory}
            /lib
            
                *.jar
            
        
        
            src/main/bin
            /
            
                start.sh
                logs
            
        
    

src/main/bin/start.sh

#!/bin/sh
dir=`cd $(dirname $0); pwd -P`
jar=$(find ./lib -type f -name  meerkat-slice-*.jar)
echo $jar
nohup java -server -Duser.dir=$dir -XX:-UseGCOverheadLimit -Xms1024m -Xmx30720m -XX:PermSize=256M -XX:MaxPermSize=512M -Dloader.path=./lib,./config -jar $jar > /dev/null &

注意事项

  • 不同的项目需要在pom.xml/build/plugins中
 		<plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <layout>ZIP</layout>
                    <includes>
                        <include>
                            <groupId>cn.wisec.meerkat</groupId> //需要换成你打包工程的groupId
                            <artifactId>meerkat-slice</artifactId>//需要换成你打包工程的artifactId
                        </include>
                    </includes>
                </configuration>
		 </plugin>
  • 在start.sh中将jar=$(find ./lib -type f -name meerkat-slice-*.jar)中的meerkat-slice改成你打包工程的artifactId

你可能感兴趣的:(springboot)