我试图找到一种方法将资源文件复制到Maven构建目标目录中的新名称.几乎我在搜索时发现的所有内容都提供了涉及多个子目录的变通方法,/src/main/resources并通过配置文件在其中进行选择.但是,在我的情况下,这并没有解决问题,即我想要的文件有一个"魔术"名称.
基本上我想要做的是将/src/main/resources/default.DS_Store文件复制到${project.build.directory}/.DS_Store.由于该.DS_Store文件在Mac OSX中具有特殊含义,因此不希望在源树和版本控制中具有该名称的文件.但是,我确实希望文件中的数据位于源树和版本控制中,并在构建期间将其重命名为"魔术"名称.
我开始认为蚂蚁是自动执行此操作的唯一方法.有没有更简单的方法?
cod*_*lus 34
使用antrun-maven-plugin可以轻松实现,但是如果您正在寻找eclipse m2e中支持的更为普遍的方式,那么您可以使用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>
Run Code Online (Sandbox Code Playgroud)
如果您对插件有任何反馈/问题,可以访问https://github.com/coderplus/copy-rename-maven-plugin/
rob*_*rse 18
用于复制和/或重命名文件的程序集插件的示例:
pom文件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<configuration>
<descriptors>
<descriptor>src/main/descriptors/example.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
描述文件:
<?xml version="1.0" encoding="UTF-8"?>
<assembly>
<id>example</id>
<formats>
<format>dir</format>
</formats>
<files>
<file>
<source>src/main/resources/something.properties</source>
<outputDirectory>/</outputDirectory>
<destName>something.properties</destName>
</file>
<file>
<source>src/main/resources/something.properties</source>
<outputDirectory>/</outputDirectory>
<destName>something_en.properties</destName>
</file>
</files>
</assembly>
Run Code Online (Sandbox Code Playgroud)
Ben*_*ine 16
我看到2个选项可以解决您的问题:
jgi*_*d25 13
您可以通过使用Maven Assembly插件和文件程序集描述符来避免Ant的问题.
P-A*_*P-A 12
我有同样的问题使用copy-rename-maven-plugin解决了我的问题
<project>
...
<build>
<plugins>
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>copy-file</id>
<phase>generate-sources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<sourceFile>src/someDirectory/test.environment.properties</sourceFile>
<destinationFile>target/someDir/environment.properties</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
69582 次 |
| 最近记录: |