为什么 maven-war-plugin 没有打包我的文件?
Why is maven-war-plugin not packaging my files?
我不知道为什么 maven-war-plugin
停止将我的文件移动到 WEB-INF/config
。这就是我使用插件的方式:
<profiles>
<profile>
<id>default-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<webResources>
<resource>
<directory>${basedir}/src/main/assembly/${package-mode}/config</directory>
<filtering>true</filtering>
<targetPath>WEB-INF/config</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
问题:我可以做些什么来再次打破它?它终于奏效了,现在它不再奏效了。
这就是我 运行 我的服务器:
mvn tomcat7:run-war -Denv=dev -Dpackage-mode=dev -DskipTests
WAR 文件已构建并打包,但 src/main/assembly/dev/config
中的那些文件根本不存在。
运行 根据你的问题下面的最小 pom:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.sample</groupId>
<artifactId>web-sample</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<profiles>
<profile>
<id>default-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<webResources>
<resource>
<directory>${basedir}/src/main/assembly/${package-mode}/config</directory>
<filtering>true</filtering>
<targetPath>WEB-INF/config</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>
并如下执行 Maven:
mvn tomcat7:run-war -Dpackage-mode=dev
文件被正确复制,正如构建日志所指定的那样:
[INFO] --- maven-war-plugin:2.6:war (default-war) @ web-sample ---
[INFO] Packaging webapp
[INFO] Assembling webapp [web-sample] in [C:\Development\workspace-mars\web-sample\target\web-sample]
[INFO] Processing war project
[INFO] Copying webapp webResources [C:\Development\workspace-mars\web-sample/src/main/assembly/dev/config] to [C:\Development\workspace-mars\web-sample\target\web-sample]
[INFO] Copying webapp resources [C:\Development\workspace-mars\web-sample\src\main\webapp]
[INFO] Webapp assembled in [106 msecs]
[INFO] Building war: C:\Development\workspace-mars\web-sample\target\web-sample.war
[INFO]
[INFO] <<< tomcat7-maven-plugin:2.0:run-war (default-cli) < package @ web-sample <<<
因此错误出在您的项目或 POM 配置中的其他地方。
我建议 运行
mvn clean
然后重试。另外,要运行一个
mvn clean package
并检查文件是否被复制,不管tomcat7插件是否执行。
我不知道为什么 maven-war-plugin
停止将我的文件移动到 WEB-INF/config
。这就是我使用插件的方式:
<profiles>
<profile>
<id>default-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<webResources>
<resource>
<directory>${basedir}/src/main/assembly/${package-mode}/config</directory>
<filtering>true</filtering>
<targetPath>WEB-INF/config</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
问题:我可以做些什么来再次打破它?它终于奏效了,现在它不再奏效了。
这就是我 运行 我的服务器:
mvn tomcat7:run-war -Denv=dev -Dpackage-mode=dev -DskipTests
WAR 文件已构建并打包,但 src/main/assembly/dev/config
中的那些文件根本不存在。
运行 根据你的问题下面的最小 pom:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.sample</groupId>
<artifactId>web-sample</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<profiles>
<profile>
<id>default-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<webResources>
<resource>
<directory>${basedir}/src/main/assembly/${package-mode}/config</directory>
<filtering>true</filtering>
<targetPath>WEB-INF/config</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>
并如下执行 Maven:
mvn tomcat7:run-war -Dpackage-mode=dev
文件被正确复制,正如构建日志所指定的那样:
[INFO] --- maven-war-plugin:2.6:war (default-war) @ web-sample ---
[INFO] Packaging webapp
[INFO] Assembling webapp [web-sample] in [C:\Development\workspace-mars\web-sample\target\web-sample]
[INFO] Processing war project
[INFO] Copying webapp webResources [C:\Development\workspace-mars\web-sample/src/main/assembly/dev/config] to [C:\Development\workspace-mars\web-sample\target\web-sample]
[INFO] Copying webapp resources [C:\Development\workspace-mars\web-sample\src\main\webapp]
[INFO] Webapp assembled in [106 msecs]
[INFO] Building war: C:\Development\workspace-mars\web-sample\target\web-sample.war
[INFO]
[INFO] <<< tomcat7-maven-plugin:2.0:run-war (default-cli) < package @ web-sample <<<
因此错误出在您的项目或 POM 配置中的其他地方。
我建议 运行
mvn clean
然后重试。另外,要运行一个
mvn clean package
并检查文件是否被复制,不管tomcat7插件是否执行。