我在pom.xml中有两个配置文件,我有一些资源文件,我已经添加到目标资源目录中:${project.build.outputDirectory}/resources
在执行第一个配置文件期间.我需要做的是在执行第二个配置文件期间删除这些资源文件.有没有办法从目标目录中删除或删除现有文件?
Kau*_*jan 32
我得到了解决方案.. !!
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<delete>
<fileset dir="${project.build.outputDirectory}/resources" includes="*.xml" />
</delete>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
供参考 - http://maven.apache.org/guides/mini/guide-building-for-different-environments.html
San*_*gen 30
我同意马修的观察,但我得到的印象是,原始海报是在询问如何自动执行clean
配置文件的(正常)"执行"期间.
您可以为Maven Clean插件定义插件执行.它通常只能绑定clean
,但通过定义插件执行,您可以绑定clean:clean
(这是插件的clean
目标clean
)到您想要的生命周期阶段.Maven Clean Plugin的文档有一个如何执行此操作的示例.该文档还有一个删除其他文件的示例.合并这两个看起来像这样:
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>auto-clean</id>
<phase>initialize</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<filesets>
<fileset>
<directory>some/relative/path</directory>
</fileset>
</filesets>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
Mat*_*ard 17
mvn clean
将删除target
目录(因此删除其中的所有文件).如果要仅从target
目录中删除某些文件,请组合使用:
excludeDefaultDirectories
阻止它删除整个目录,和
filesets
告诉它要删除什么
参考:http://maven.apache.org/plugins/maven-clean-plugin/clean-mojo.html
使用Apache Maven AntRun Plugin 1.8的解决方案:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<delete
dir="${project.build.outputDirectory}/resources"
includeemptydirs="true"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我只需要从输出目录中删除几个文件,以下对我来说效果很好。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<delete file="${project.build.outputDirectory}/appContextLocal.xml" />
<delete
file="${project.build.outputDirectory}/appContextServer.xml" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我还认为你可以在这里运行任何 ant 命令来替换你需要的任何任务<tasks> .... </tasks>
,它会起作用。
您可以执行的蚂蚁任务列表在这里
参考:http : //maven.apache.org/plugins/maven-antrun-plugin/usage.html
感谢以上答案。最后我来到了类似的东西:
if you want to just delete some directories in target folder, you have to create some construct like this.
this for instance deletes just all contents of folders:
excludeDefaultDirectories allows to not delete complete target folder.
i used it to clean up target folder before lint analysis.
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>Deleting all unnecessary files before lint analysis</id>
<phase>verify</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<filesets>
<fileset>
<directory>target/unpack</directory>
<followSymlinks>false</followSymlinks>
<excludes>
<exclude>*</exclude>
</excludes>
</fileset>
<fileset>
<directory>gen-external-apklibs</directory>
<followSymlinks>false</followSymlinks>
<excludes>
<exclude>*</exclude>
</excludes>
</fileset>
</filesets>
<verbose>true</verbose>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
73594 次 |
最近记录: |