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

springboot maven-resources-plugin使用

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

springboot maven-resources-plugin使用


springboot maven-resources-plugin使用

                              

官网:Apache Maven Resources Plugin – Introduction

                                   

                                            

**********************

maven resources plugin

                        

The Resources Plugin handles the copying of project resources to the output directory. 
# resources插件用来把项目文件复制到output directory

There are two different kinds of resources: main resources and test resources. 
The difference is that the main resources are the resources associated to the main source code while the test resources are associated to the test source code.
# 资源类型有两种:main resources、test resources
# main resources和main 源代码相关联
# test resources和test 源代码相关联

Thus, this allows the separation of resources for the main source code and its unit tests
# 因此,可以将main rsources、单元测试代码分离开来

                                

resources goals

# resources:resources
copies the resources for the main source code to the main output directory.
This goal usually executes automatically, because it is bound by default to the process-resources life-cycle phase. It always uses the project.build.resources element to specify the resources, and by default uses the project.build.outputDirectory to specify the copy destination.
# 复制main resources到main output目录,默认自动执行
# 源文件:project.build.resources
# output directory:project.build.outputDirectory (target/classes)

# resources:testResources 
copies the resources for the test source code to the test output directory.
This goal usually executes automatically, because it is bound by default to the process-test-resources life-cycle phase. It always uses the project.build.testResources element to specify the resources, and by default uses the project.build.testOutputDirectory to specify the copy destination.
# 复制test resources到test output目录,默认自动执行
# 源文件:project.build.testResources
# output directory:project.build.testOutputDirectory (target/test-classes)

# resources:copy-resources 
copies resources to an output directory.
This goal requires that you configure the resources to be copied, and specify the outputDirectory
# 复制resources到指定目录
# 不会自动执行,需要自行配置需要复制的资源、输出的目录

                                    

resources:resources goal 参数说明

# 必选参数
outputDirectory:资源输出目录,默认为:${project.build.outputDirectory}

# 可选参数
addDefaultExcludes:.gitignore, .cvsignore等文件默认不会复制
                    设置false,可复制所有文件

delimiters:资源文件分隔符

  ${*}
  @


includeEmptyDirs:是否复制空的目录,默认为false
encoding:读、写过滤资源文件使用的编码,默认为:${project.build.sourceEncoding}
escapeString:转义符,默认为:
escapeWindowsPaths:Whether to escape backslashes and colons in windows-style paths
                    默认为true

fileNameFiltering:是否支持过滤文件夹,默认为false
filters:过滤的文件

mavenFilteringHints:过滤提示
nonFilteredFileExtensions:不过滤的文件拓展,默认: jpg, jpeg, gif, bmp, png(这些文件不会过滤)

overwrite:output directory文件更新时,是否进行覆盖,默认false
propertiesEncoding:属性文件编码,如果没有设置,默认为系统encoding的值

skip:是否不执行该goal,不推荐(Its use is NOT RECOMMENDED, but quite convenient on occasion)
      默认为false
supportMultiLineFiltering:是否支持多行过滤,默认为false
useBuildFilters:build时是否过滤,默认为true
useDefaultDelimiters:是否使用默认分隔符,默认为true

                                       

resources:testResources goal 参数说明

# 必选参数
outputDirectory:资源输出目录,默认为:${project.build.outputDirectory}
resources:需要复制的test资源,默认为:${project.testResources}

# 可选参数
addDefaultExcludes:.gitignore, .cvsignore等文件默认不会复制
                    设置false,可复制所有文件
 
delimiters:资源文件分隔符

  ${*}
  @

 
includeEmptyDirs:是否复制空的目录,默认为false
encoding:读、写过滤资源文件使用的编码,默认为:${project.build.sourceEncoding}
escapeString:转义符,默认为:
escapeWindowsPaths:Whether to escape backslashes and colons in windows-style paths
                    默认为true
 
fileNameFiltering:是否支持过滤文件夹,默认为false
filters:过滤的文件
 
mavenFilteringHints:过滤提示
nonFilteredFileExtensions:不过滤的文件拓展,默认: jpg, jpeg, gif, bmp, png(这些文件不会过滤)
 
overwrite:output directory文件更新时,是否进行覆盖,默认false
propertiesEncoding:属性文件编码,如果没有设置,默认为系统encoding的值
 
skip:是否不执行该goal,不推荐(Its use is NOT RECOMMENDED, but quite convenient on occasion)
      默认为false
supportMultiLineFiltering:是否支持多行过滤,默认为false
useBuildFilters:build时是否过滤,默认为true
useDefaultDelimiters:是否使用默认分隔符,默认为true

                                     

resources:copyResources goal 参数说明

# 必选参数
outputDirectory:资源输出目录,需自定义
resources:需要复制的资源,需自定义

# 可选参数
addDefaultExcludes:.gitignore, .cvsignore等文件默认不会复制
                    设置false,可复制所有文件
 
delimiters:资源文件分隔符

  ${*}
  @

 
includeEmptyDirs:是否复制空的目录,默认为false
encoding:读、写过滤资源文件使用的编码,默认为:${project.build.sourceEncoding}
escapeString:转义符,默认为:
escapeWindowsPaths:Whether to escape backslashes and colons in windows-style paths
                    默认为true
 
fileNameFiltering:是否支持过滤文件夹,默认为false
filters:过滤的文件
 
mavenFilteringHints:过滤提示
nonFilteredFileExtensions:不过滤的文件拓展,默认: jpg, jpeg, gif, bmp, png(这些文件不会过滤)
 
overwrite:output directory文件更新时,是否进行覆盖,默认false
propertiesEncoding:属性文件编码,如果没有设置,默认为系统encoding的值
 
skip:是否不执行该goal,不推荐(Its use is NOT RECOMMENDED, but quite convenient on occasion)
      默认为false
supportMultiLineFiltering:是否支持多行过滤,默认为false
useBuildFilters:build时是否过滤,默认为true
useDefaultDelimiters:是否使用默认分隔符,默认为true

                                                                                     

                                                                             

**********************

示例

                        

pom.xml



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.5.5
         
    
    com.example
    demo
    0.0.1-SNAPSHOT
    demo
    Demo project for Spring Boot
    
        11
    
    
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.boot
            spring-boot-configuration-processor
            true
        
        
            org.projectlombok
            lombok
            true
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    

    
        hello
        
            
                org.springframework.boot
                spring-boot-maven-plugin
                
                    
                        
                            org.projectlombok
                            lombok
                        
                    
                
            

            
                org.apache.maven.plugins
                maven-resources-plugin
                3.2.0
                
                    
                        copy-resources
                        package
                        
                            copy-resources
                        
                        
                        
                            ${project.build.directory}/resources
                            
                                
                                    
                                    ${project.build.directory}/java
                                    src/main/java
                                
                                    
                                
                                    src/main/resources
                                
                            
                        
                    
                
            
        
    


                         

说明:直接在build标签设置resources实现相同效果

    
        hello
        
            
                org.springframework.boot
                spring-boot-maven-plugin
                
                    
                        
                            org.projectlombok
                            lombok
                        
                    
                
            
        

        
            
                ${project.build.directory}/java
                src/main/java
            
            
                ${project.build.directory}/resources
                src/main/resources
            
        
    

                            

maven 打包

                                  

src/main/java 复制到了target/java目录

src/main/resources 复制到了 target/resources目录

                         

                                         

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

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

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