为了让我的生活更轻松,我将我的 maven 配置为将我部署的应用程序放在/deploy
与默认文件夹不同的文件夹 ( ) 中(因此它不会与classes/
,surefire-reports
目录等混合)。它工作正常,除了当我尝试运行mvn clean
时,它只删除 jar 和复制的依赖项,而不是复制的资源。
更新看来它们正在被删除,但随后立即被放回。它似乎与使用 Eclipse 和 相关Build Automatically
,但我不确定为什么更改 Maven 的配置会对 Eclipse 产生这种影响。结束更新
更新 2目前,没有一个答案是正确的。这个问题显然与目录无关deploy
;似乎maven-resources-plugin使 Eclipse 复制资源作为Build Automatically的一部分。但是我不确定如何在不停止使用maven-resources-plugin 的情况下关闭它,并且在不停止使用Build Automatically的情况下,我会将赏金提供给能够解释如何执行此操作的人。结束更新 2
无论如何,我的目录看起来像这样:
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
这是我的pom
片段:
<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>