我想根据配置文件集排除将文件夹添加到.war文件中。
我有以下配置:
<profile>
<id>tomcat</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>env</name>
<value>tomcat</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<webResources>
<resource>
<directory>src/main/webapp</directory>
<excludes>
<exclude>docs/*</exclude>
</excludes>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
<finalName>somename</finalName>
</build>
<properties>
<webXmlPath>${basedir}/src/main/config/tomcat</webXmlPath>
<profileDir>tomcat</profileDir>
</properties>
</profile>
插件的配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<webXml>${webXmlPath}/web.xml</webXml>
<webResources>
<resource>
<directory>src/main/webapp</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/js/*</exclude>
<exclude>**/css/*</exclude>
<exclude>**/fonts/*</exclude>
<exclude>**/web.xml</exclude>
<exclude>**/config/*</exclude>
</excludes>
</resource>
</webResources>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>gif</nonFilteredFileExtension>
<nonFilteredFileExtension>ico</nonFilteredFileExtension>
<nonFilteredFileExtension>jpg</nonFilteredFileExtension>
<nonFilteredFileExtension>png</nonFilteredFileExtension>
<nonFilteredFileExtension>pdf</nonFilteredFileExtension>
<nonFilteredFileExtension>otf</nonFilteredFileExtension>
<nonFilteredFileExtension>eot</nonFilteredFileExtension>
<nonFilteredFileExtension>svg</nonFilteredFileExtension>
<nonFilteredFileExtension>ttf</nonFilteredFileExtension>
<nonFilteredFileExtension>woff</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
应该过滤docs文件夹,但它存在于内置文件中。 我也试过
<warSourceExcludes>docs/**</warSourceExcludes>
但这也不起作用。
这是调试输出:
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-war-plugin:2.2:war' with basic configurator -->
[DEBUG] (s) archiveClasses = false
[DEBUG] (s) attachClasses = false
[DEBUG] (s) cacheFile = C:\dev\workspaces\pep3_intellij\target\war\work\webapp-cache.xml
[DEBUG] (s) classesClassifier = classes
[DEBUG] (s) classesDirectory = C:\dev\workspaces\pep3_intellij\target\classes
[DEBUG] (f) escapedBackslashesInFilePath = false
[DEBUG] (s) failOnMissingWebXml = true
[DEBUG] (f) filteringDeploymentDescriptors = false
[DEBUG] (s) nonFilteredFileExtensions = [gif, ico, jpg, png, pdf, otf, eot, svg, ttf, woff]
[DEBUG] (s) outputDirectory = C:\dev\workspaces\pep3_intellij\target
[DEBUG] (s) primaryArtifact = true
[DEBUG] (s) project = MavenProject: <censored>:0.4 @ C:\dev\workspaces\pep3_intellij\pom.xml
[DEBUG] (f) session = org.apache.maven.execution.MavenSession@138684e7
[DEBUG] (s) warName = pep
[DEBUG] (s) useCache = false
[DEBUG] (s) warSourceDirectory = C:\dev\workspaces\pep3_intellij\src\main\webapp
[DEBUG] (s) warSourceIncludes = **
[DEBUG] (s) directory = src/main/webapp
[DEBUG] (s) excludes = [docs/**]
[DEBUG] (s) filtering = true
[DEBUG] (s) webResources = [Resource {targetPath: null, filtering: true, FileSet {directory: src/main/webapp, PatternSet [includes: {}, excludes: {docs/**}]}}]
[DEBUG] (s) webappDirectory = C:\dev\workspaces\pep3_intellij\target\pep
[DEBUG] (s) webXml = C:\dev\workspaces\pep3_intellij\src\main\config\tomcat\web.xml
[DEBUG] (s) workDirectory = C:\dev\workspaces\pep3_intellij\target\war\work
[DEBUG] -- end configuration --
正确选择了配置文件,通过检查 mvn help:active-profiles
[INFO] Active Profiles for Project '<myproject>:0.4':
The following profiles are active:
- tomcat (source: <myproject>:0.4)
我对 - 属性有点困惑,没有找到一个好的解释,唯一接近它的是Filtering in Maven War Plugin,但它没有解释何时以及为何使用。