To make my life easier, I configured my maven to put my deployed application in a different folder (/deploy
) than the default (so it doesn't mix with classes/
, surefire-reports
directories and so forth). It works fine, except that when I try to run mvn clean
, it only deletes the jar and copied dependencies, but NOT the copied resources.
UPDATE It appears they are being deleted, but then get placed back immediately. It appears to be related to using Eclipse and Build Automatically
, but I'm not sure why changing Maven's configuration would have this effect on Eclipse. END UPDATE
UPDATE 2 At the present moment, none of the answers are correct. This problem clearly has little to do with the deploy
directory; it seems that maven-resources-plugin makes Eclipse copy resources as part of Build Automatically. But I'm not sure how to turn this off without stopping using maven-resources-plugin, and without stopping using Build Automatically I will give the bounty to someone who can explain how to do this. END UPDATE 2
Anyway, my directory looks something like this:
my-app
|-- pom.xml
|-- src
| |-- main
| | |-- java
| | `-- resources
| | |-- script.sh
| | `-- config
| | `-- app.properties
| `-- test
| |-- java
| `-- resources
`-- deploy
|-- my-app.jar <----- This gets deleted correctly
|-- lib <----- This gets deleted correctly
| |-- dependency1.jar <----- This gets deleted correctly
| |-- dependency2.jar <----- This gets deleted correctly
|-- config <----- This DOES NOT get deleted correctly
| `-- app.properties <----- This DOES NOT get deleted correctly
`-- script.sh <----- This DOES NOT get deleted correctly
Here's my pom
snippet:
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven.jar.version}</version>
<configuration>
<archive>
<manifest>
<mainClass>my.main.Class</mainClass>
<packageName>my.main</packageName>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
<excludes>
<exclude><!-- the files I don't want in my jar --></exclude>
</excludes>
<outputDirectory>${basedir}/deploy</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/deploy/lib</outputDirectory>
<includeScope>compile</includeScope>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/deploy</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<configuration>
<filesets>
<fileset>
<directory>deploy</directory>
<includes>
<include>**/*</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
The Maven Clean Plugin will delete the target directory by default. You may configure it to delete additional directories and files. The following example shows how: <build>
mvn clean do not clean your repository. It only cleans the project. Save this answer.
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.
On Maven, each time you want to compile, the best practice is to run mvn clean . It clears out the existing classes that you compiled from last compile. If you don't want to run 3 lines, just do "mvn test" after mvn clean . You don't have to always do mvn compile .
Stick to the Maven way and put your deploy
directory under ${basedir}/target
then your problem will fix itself. You can remove the custom plugin configuration for the clean plugin as well.
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