I have two profiles in pom.xml, and I have some resource files which I have added into target resource directory: ${project.build.outputDirectory}/resources
during execution of the first profile. What I need to do is remove those resource files during execution of the second profile. Is there any way to remove or delete existing files from target directory?
To delete the target directory, run mvn clean on your project directly from the command line. That will delete the target directory as expected. In contrast, running Run As > Maven clean from Eclipse for some reason leaves the target directory and subdirectories classes and test-classes.
When “mvn clean” is executed, everything under “target” folder will be deleted.
Explanation. mvn clean command removes the target directory with all the build data before starting the build process.
so go and delete folder manually by using Windows Explorer if not open a windows explorer with administrative right and then go to that folder and delete. now you can run mvn clean install it will works fine.
To remove non-empty directories and all the files within them, use the rm command with the -r (recursive) option: If a directory or a file within the directory is write-protected, you will be prompted to confirm the deletion. To remove non-empty directories and all the files without being prompted, use rm with the -r (recursive) and -f options:
To remove non-empty directories and all the files without being prompted, use rm with the -r (recursive) and -f options: To remove multiple directories at once, use the rm -r command followed by the directory names separated by space. Same as with files you can also use a wildcard ( *) and regular expansions to match multiple directories.
If you leave it empty, the deletions are done from the root folder of the repository (same as if you had specified $ (Build.SourcesDirectory) ). If your build produces artifacts outside of the sources directory, specify $ (Agent.BuildDirectory) to delete files from the build agent working directory. (Required) File/folder paths to delete.
If a directory or a file within the directory is write-protected, you will be prompted to confirm the deletion. To remove non-empty directories and all the files without being prompted, use rm with the -r (recursive) and -f options:
I got the solution..!!
<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>
for reference - http://maven.apache.org/guides/mini/guide-building-for-different-environments.html
I do agree with Matthew's observations, but I got the impression that the original poster was asking how to automate execution of clean
during (normal) "execution" of a profile.
You can define a plugin execution for the Maven Clean Plugin. It is normally only bound to clean
, but by defining a plugin execution you can bind clean:clean
(that is the clean
goal of the clean
plugin) to whichever lifecycle phase you want. The documentation of the Maven Clean Plugin has an example of how to do this. The documentation also has an example of deleting additional files. Merged the two looks like this:
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With