Keep smile !
分类: Java
2016-11-17 22:12:34
注意:打包后的.war 包中已经没有excludes的文件 ,但生成的同名目录中还有!所以这个功能 可能 在将 目录转换成.war包时起作用
=====================================================
It is possible to include or exclude certain files from the WAR file, by using the
WEB-INF/lib/commons-logging-*.jar,
%regex[WEB-INF/lib/log4j-(?!over-slf4j).*.jar]
=======================================================================================
The default resource directory for all Maven projects is src/main/resources which will end up in target/classes and in WEB-INF/classes in the WAR. The directory structure will be preserved in the process.
The WAR Plugin is also capable of including resources not found in the default resource directory through thewebResources parameter.
... ... org.apache.maven.plugins maven-war-plugin 3.0.0 resource2
Using our sample project in the with an added external resource, like this:
. |-- pom.xml |-- resource2 | |-- external-resource.jpg | `-- image2 | `-- external-resource2.jpg `-- src `-- main |-- java | `-- com | `-- example | `-- projects | `-- SampleAction.java |-- resources | `-- images | `-- sampleimage.jpg `-- webapp |-- WEB-INF | `-- web.xml |-- index.jsp `-- jsp `-- websource.jsp
would end up in the WAR as:
documentedproject-1.0-SNAPSHOT.war |-- META-INF | |-- MANIFEST.MF | `-- maven | `-- com.example.projects | `-- documentedproject | |-- pom.properties | `-- pom.xml |-- WEB-INF | |-- classes | | |-- com | | | `-- example | | | `-- projects | | | `-- SampleAction.class | | `-- images | | `-- sampleimage.jpg | `-- web.xml |-- external-resource.jpg |-- image2 | `-- external-resource2.jpg |-- index.jsp `-- jsp `-- websource.jsp
external-resource2.jpg and image2 are copied to the root of the WAR, preserving the directory structure.
webResources is a list of resources. All options of resource are supported.
A web resource
can have includes/excludes
can be filtered
is not limited to the default destination - the root of the WAR
To include all jpgs in the WAR we can add the following to our POM configuration from above:
...... resource2 **/*.jpg
To exclude the image2 directory from the WAR add this:
...... resource2 **/image2
Be careful when mixing includes and excludes, excludes will have a higher priority. Includes can not override excludes if a resource matches both.
Having this configuration will exclude all jpgs from the WAR:
...... resource2/ image2/*.jpg **/*.jpg
Here's another example of how to specify include and exclude patterns:
...... resource2 **/pattern1 *pattern2 *pattern3/pattern3 pattern4/pattern4
Using our example above, we can also configure filters for our resources. We will add a hypothetical configurationsdirectory to our project:
. |-- configurations | |-- config.cfg | `-- properties | `-- config.prop |-- pom.xml |-- resource2 | |-- external-resource.jpg | `-- image2 | `-- external-resource2.jpg `-- src `-- main |-- java | `-- com | `-- example | `-- projects | `-- SampleAction.java |-- resources | `-- images | `-- sampleimage.jpg `-- webapp |-- WEB-INF | `-- web.xml |-- index.jsp `-- jsp `-- websource.jsp
To prevent corrupting your binary files when filtering is enabled, you can configure a list of file extensions that will not be filtered.
...config.prop... properties/config.prop resource2 false configurations true **/properties
interpolated_property=some_config_valueconfig.cfg
${interpolated_property}
The resulting WAR would be:
documentedproject-1.0-SNAPSHOT.war |-- META-INF | |-- MANIFEST.MF | `-- maven | `-- com.example.projects | `-- documentedproject | |-- pom.properties | `-- pom.xml |-- WEB-INF | |-- classes | | |-- com | | | `-- example | | | `-- projects | | | `-- SampleAction.class | | `-- images | | `-- sampleimage.jpg | `-- web.xml |-- config.cfg |-- external-resource.jpg |-- image2 | `-- external-resource2.jpg |-- index.jsp `-- jsp `-- websource.jsp
and the content of config.cfg would be:
some_config_value
Note: In versions 2.2 and earlier of this plugin the platform encoding was used when filtering resources. Depending on what that encoding was you could end up with scrambled characters after filtering. Starting with version 2.3 this plugin respects the property project.build.sourceEncoding when filtering resources. One notable exception to this is that.xml files are filtered using the encoding specified inside the xml-file itself.
By default web resources are copied to the root of the WAR, as shown in the previous example. To override the default destination directory, specify the target path.
...... ... configurations WEB-INF true **/properties
Using the sample project the resulting WAR would look like this:
documentedproject-1.0-SNAPSHOT.war |-- META-INF | |-- MANIFEST.MF | `-- maven | `-- com.example.projects | `-- documentedproject | |-- pom.properties | `-- pom.xml |-- WEB-INF | |-- classes | | |-- com | | | `-- example | | | `-- projects | | | `-- SampleAction.class | | `-- images | | `-- sampleimage.jpg | |-- config.cfg | `-- web.xml |-- external-resource.jpg |-- image2 | `-- external-resource2.jpg |-- index.jsp `-- jsp `-- websource.jsp