详解Spring Boot使用Maven自定义打包方式

前言:本文将告诉你如何将程序Jar与与依赖Jar及配置文件分离打包,以下列举了两种不同Maven打包方式,其打包效果一致!

一、第一种Maven打包方式,将jar及resources下全部配置文件,拷贝到指定目录:

  E:/IDEAFile/file-copy/target/project

  
   
   
    org.springframework.boot
    spring-boot-maven-plugin
   

   
   
    org.apache.maven.plugins
    maven-jar-plugin
    2.6
    
     
      
       true
       lib/
       com.example.filecopy.FileCopyApplication
      
     
    
   

  
   
    maven-resources-plugin
    
     
      copy-resources
      validate
      
       copy-resources
      
      
       ${project.build.directory}/project
       
        
         src/main/resources
         true
        
       
      
     
    
   

   
   
    maven-antrun-plugin
    
     
      
      package
      
       
        
        
         
         
          
         
        
       
      
      
       run
      
     
    
   
  
 

第二种Maven打包方式使用 assembly插件,将jar及配置文件进行压缩打包到指定目录:


   
   
    org.springframework.boot
    spring-boot-maven-plugin
   

   
   
    org.apache.maven.plugins
    maven-jar-plugin
    2.6
    
     
      
       true
       lib/
       com.example.filecopy.FileCopyApplication
      
     
    
   

    
   
    org.apache.maven.plugins
    maven-assembly-plugin
    2.4
    
     
     project
     
     
      /assembly/assembly.xml
     
     
     ${project.build.directory}
     false
    
    
     
      package
      
       single
      
     
    
   
  

assembly文件:


 leaves
 
  
  zip
 
 true

 
 
  
  
   ${basedir}/src/main/resources
   
    **
   
   true
   ${file.separator}
  

  
  
   ${project.build.directory}
   ${file.separator}
   
    *.jar
   
  
 

到此这篇关于Spring Boot使用Maven自定义打包方式的文章就介绍到这了,更多相关Spring Boot Maven自定义打包内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

你可能感兴趣的:(详解Spring Boot使用Maven自定义打包方式)