Chinaunix首页 | 论坛 | 博客
  • 博客访问: 57520
  • 博文数量: 17
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 237
  • 用 户 组: 普通用户
  • 注册时间: 2013-05-15 06:01
个人简介

Keep smile !

文章分类

全部博文(17)

文章存档

2016年(10)

2013年(7)

我的朋友

分类: Java

2016-11-17 22:12:34

   org.apache.maven.plugins

   maven-war-plugin

   2.4

   

 

           src/main/webapp

           

               node_modules/**/*.*

Gruntfile.js

               

         

       

   

麦库截图20162217220129378.jpg 

注意:打包后的.war 包中已经没有excludes的文件 ,但生成的同名目录中还有!所以这个功能 可能 在将 目录转换成.war包时起作用

=====================================================

It is possible to include or exclude certain files from the WAR file, by using the  and  configuration parameters. They each take a comma-separated list of Ant file set patterns. You can use wildcards such as ** to indicate multiple directories and * to indicate an optional part of a file or directory name.

  1.          

  2.          

  3.            WEB-INF/lib/commons-logging-*.jar,

  4.            %regex[WEB-INF/lib/log4j-(?!over-slf4j).*.jar]

  5.          

  6.        

=======================================================================================

Adding and Filtering External Web Resources

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.

Adding web resources

  ...                    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.

Configuring web Resources

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

Includes/Excludes

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                                                    ...

Filtering

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.

        ...                                                  properties/config.prop                                            pdf                                              resource2                            false                                      configurations                            true                              **/properties                                                    ...
config.prop
interpolated_property=some_config_value
config.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.

Overriding the default destination directory

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


阅读(623) | 评论(0) | 转发(0) |
0

上一篇:pom.xml中各个标签 的意思

下一篇:没有了

给主人留下些什么吧!~~