Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven - how to delete contents of a folder during a clean phase?

Tags:

maven-2

maven

in my project I have a folder called war. It is initially empty and it's under version control. The folder gets populated by Maven during its package phase and Eclipse's WST plugin deploys the web app from this folder.

What I want is to delete contents of the war folder during the clean phase but not the folder itself. How do I do that? So far I know how to delete the whole war folder:

<plugin>     <groupId>org.apache.maven.plugins</groupId>     <artifactId>maven-clean-plugin</artifactId>     <version>2.4.1</version>     <configuration>         <followSymLinks>false</followSymLinks>         <filesets>             <fileset>                 <directory>${basedir}/war</directory>             </fileset>         </filesets>     </configuration> </plugin> 

How do I delete only contents of the war folder but not the folder itself? I know that by adding some existing excludes, the folder won't be deleted. But how to generally delete only contents of a folder?

like image 504
janhink Avatar asked Apr 18 '11 11:04

janhink


People also ask

Does mvn clean delete target?

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

What happens when Maven clean?

The Maven Clean Plugin, as the name implies, attempts to clean the files and directories generated by Maven during its build. While there are plugins that generate additional files, the Clean Plugin assumes that these files are generated inside the target directory.

How do I clear my target folder?

To delete the target directory, run mvn clean on your project directly from the command line. That will delete the target directory as expected.

What is Maven clean command?

mvn clean: Cleans the project and removes all files generated by the previous build. mvn compile: Compiles source code of the project. mvn test-compile: Compiles the test source code.


2 Answers

Add this includes section to your fileset definition

<build>     <plugins>         <plugin>             <groupId>org.apache.maven.plugins</groupId>             <artifactId>maven-clean-plugin</artifactId>             <version>2.4.1</version>             <configuration>                 <filesets>                     <fileset>                         <directory>war</directory>                         <includes>                             <include>**/*</include>                         </includes>                         <followSymlinks>false</followSymlinks>                     </fileset>                 </filesets>             </configuration>         </plugin>     </plugins> </build> 
like image 138
FrVaBe Avatar answered Sep 28 '22 05:09

FrVaBe


In my case I needed to delete the "bin" directory, and all it's subdirectory contents. I did this in my parent pom.xml:

<fileset>     <directory>${basedir}</directory>       <includes>         <include>**/bin/**</include>       </includes>        <followSymlinks>false</followSymlinks> </fileset> 

This found any bin directory within my project, and deleted any contents of the bin folder.

like image 23
Jason K Avatar answered Sep 28 '22 06:09

Jason K