Maven 插件之 resources 插件

https://blog.csdn.net/u014297148/article/details/80946158

1.Apache Maven Resources Plugin

官网对该插件的详解见官方文档地址

The Resources Plugin handles the copying of project resources to the 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.
该插件的作用 主要是处理将 主程序与 测试程序所需的源文件复制到输出编译文件夹中。

2.使用场景

2.1 指定源文件编译的字符编码

a.第一种方式在properites设置

   
     ...
     
       UTF-8
       ...
     

     ..
   

b.在构建路径中指定


   
     
        org.apache.maven.plugins
        maven-resources-plugin
        3.1.0
       
          ...
          UTF-8
          ...
       

     

   

    ...
 

2.2 指定自定义的resources 路径

By default, Maven will look for your project’s resources under src/main/resources.
However, all your resources may not be in src/main/resources. Thus, you’d have to specify those directories by adding the following to your POM.


   ...
   
     
       [your folder here]
     

   

   ...
 

2.3 是否启动筛选

Variables can be included in your resources. These variables, denoted by the ${…} delimiters, can come from the system properties, your project properties, from your filter resources and from the command line.
变量可以包含在您的资源中。 这些变量由$ {…}分隔符表示,可以来自系统属性,项目属性,过滤器资源和命令行。

 

这里显示${name}在编译后的 hello.txt里还是 原文输出 
 
而开启了filter过滤后则会取resources下 属性为name的value

为了不改变pom原有的属性,你可以在 里面设置你的k-v 如 you.name=world,在 编译打包的时候同样可以获取到值 


你也可以将你想获取的k-v 单独的写在一个配置文件并防止resources下 在 build-> filters->filter 设置属性文件名 


Do not filter files with binary content like images! This will most likely result in corrupt output.
不要过滤像图像这样的二进制内容的文件! 这很可能会导致输出损坏。所以可以将这两种文件分别放在一个过滤的文件和一个不过滤的文件件内

3.使用示例

在eureka的构建时候有一个info的页面需要一个项目的构建信息我们可以在 yml 配置文件中配置

info: 
  app.name: javxuan-app
  company.name: javxuan.group.com
  build.artifactId: $project.artifactId$
  build.version: $project.version$

        microservicecloud
//表示在 

   
            src/main/resources
                true
   



   
        org.apache.maven.plugins
        maven-resources-plugin
           
           
            //表示取resources中以$*$的信息
            $
           

           

       

   


4. 你可以指定和排除参与构建的resoures


5.将不在maven默认构建的resources的文件 里资源 copy 到目标目录


--------------------- 
作者:Javxuan 
来源:CSDN 
原文:https://blog.csdn.net/u014297148/article/details/80946158 
版权声明:本文为博主原创文章,转载请附上博文链接!


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部