---
title: "Maven文件重命名"
author: "sunjing"
date: "2017-05-07T14:09:47Z"
tags: []
categories: ["开源软件"]
slug: "maven"
draft: false
lastmod: "2017-05-07T14:16:40Z"
id: 2373011
url: "https://billben.iteye.com/blog/2373011"
---

最近一直在做老系统的升级项目，其中不同环境的配置文件使用了不同的名字，那怎样利用Maven重命名文件呢？可以使用copy-rename-maven-plugin插件，如下：

 

&lt;build&gt;  
    &lt;resources&gt;  
        &lt;resource&gt;  
            &lt;directory&gt;src/main/resources&lt;/directory&gt;  
            &lt;excludes&gt;  
                &lt;exclude&gt;config.properties&lt;/exclude&gt;  
            &lt;/excludes&gt;  
        &lt;/resource&gt;  
    &lt;/resources&gt;  
    &lt;plugins&gt;  
        &lt;plugin&gt;  
            &lt;groupId&gt;com.coderplus.maven.plugins&lt;/groupId&gt;  
            &lt;artifactId&gt;copy-rename-maven-plugin&lt;/artifactId&gt;  
            &lt;executions&gt;  
                &lt;execution&gt;  
                    &lt;id&gt;rename-file&lt;/id&gt;  
                    &lt;phase&gt;compile&lt;/phase&gt;  
                    &lt;goals&gt;  
                        &lt;goal&gt;rename&lt;/goal&gt;  
                    &lt;/goals&gt;  
                    &lt;configuration&gt;  
                        &lt;sourceFile&gt;${project.build.outputDirectory}/config-dev.properties&lt;/sourceFile&gt;  
                        &lt;destinationFile&gt;${project.build.outputDirectory}/config.properties&lt;/destinationFile&gt;  
                    &lt;/configuration&gt;  
                &lt;/execution&gt;  
            &lt;/executions&gt;  
        &lt;/plugin&gt;  
    &lt;/plugins&gt;  
&lt;/build&gt;

 

使用不同的文件，维护复杂，也不容易看出不同环境的区别，最好修改为使用properties。