Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
395 views
in Technique[技术] by (71.8m points)

Renaming resources in Maven

I am trying to find a way to copy a resource file to a new name in the target directory in a Maven build. Pretty much everything I have found while searching suggests workarounds involving multiple sub-directories in /src/main/resources and selecting among them via profiles. However, in my case, this does not solve the problem, namely that the file I want has a "magic" name.

Basically what I want to do is have a /src/main/resources/default.DS_Store file get copied to ${project.build.directory}/.DS_Store. Since the .DS_Store file has special meaning in Mac OSX, it is not desirable to have a file with that name in the source tree, and in version control. However, I do want the data in the file to be in the source tree and version control, and have it renamed to the "magic" name during the build.

I'm starting to think that ant is the only way to do this automatically. Is there any easier way?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Using the antrun-maven-plugin makes it easy, but in case you are looking for a more mavenish way which is supported within eclipse m2e, then you can use the copy-rename-maven-plugin

  <plugin>
    <groupId>com.coderplus.maven.plugins</groupId>
    <artifactId>copy-rename-maven-plugin</artifactId>
    <version>1.0.1</version>
    <executions>
      <execution>
        <id>rename-file</id>
        <phase>compile</phase>
        <goals>
          <goal>rename</goal>
        </goals>
        <configuration>
          <sourceFile>${project.build.outputDirectory}/default.DS_Store</sourceFile>
          <destinationFile>${project.build.outputDirectory}/.DS_Store</destinationFile>
        </configuration>
      </execution>
    </executions>
  </plugin>

And in case you have any feedback/issues with the plugin, you can reach out at https://github.com/coderplus/copy-rename-maven-plugin/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...