Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove or delete resource files from target directory using pom file

Tags:

maven

pom.xml

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?

like image 282
Kaustubh Najan Avatar asked Sep 05 '13 13:09

Kaustubh Najan


People also ask

Can we delete target folder in Maven?

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.

Does mvn clean delete target?

When “mvn clean” is executed, everything under “target” folder will be deleted.

Which of the following commands is used to remove the files that are generated in target folder?

Explanation. mvn clean command removes the target directory with all the build data before starting the build process.

How do I delete a target folder?

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.

How do I delete non-empty directories and files in a directory?

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:

How do I delete multiple directories in Linux without being prompted?

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.

How to delete files from the build agent working directory?

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.

How do I delete a write protected directory in Linux?

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:


2 Answers

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

like image 174
Kaustubh Najan Avatar answered Sep 21 '22 15:09

Kaustubh Najan


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> 
like image 20
Sander Verhagen Avatar answered Sep 19 '22 15:09

Sander Verhagen