说明

翻译maven-war-plugin插件的部分内容

官方地址为:https://maven.apache.org/plugins/maven-war-plugin/index.html


Overview

概述

Introduction

介绍

Apache Maven WAR Plugin

apache maven war 插件

The WAR Plugin is responsible for collecting all artifact dependencies, classes and resources of the web application and packaging them into a web application archive.

war插件负责收集web工程中所有的依赖引用、class文件和资源文件,并将它们打包到一个web工程存档中

Goals Overview

目标概述

  • war:war is the default goal invoked during the package phase for projects with a packaging type of war. It builds a WAR file.

  • 当项目的打包类型为war时,war:war是一个默认的目标在package执行阶段被调用

  • war:exploded is generally used to speed up testing during the developement phase by creating an exploded webapp in a specified directory.

  • war:exploded用来在指定的目录下创建一个解包的webapp,这通常用来在开发阶段提升测试速度

  • war:inplace another variation of war:explode where the webapp is instead generated in the web application source directory, which is src/main/webapp by default.

  • war:inplace是war:explode的一个变体,会在web工程的源目录下创建webapp,默认的目录是src/main/webapp

Usage

用法

General instructions on how to use the WAR Plugin can be found on the usage page. Some more specific use cases are described in the examples given below. To share common resources across multiple web applications, see the documentation about using overlays.

关于如何使用war插件的整体介绍在usage页面可以找到。后面的examples中会给出一些更具体的使用案例。要在多个web工程中共享公共资源,请参阅有关使用overlays的文档

In case you still have questions regarding the plugin’s usage, please have a look at the FAQ and feel free to contact the user mailing list. The posts to the mailing list are archived and could already contain the answer to your question as part of an older thread. Hence, it is also worth browsing/searching the mail archive.

If you feel like the plugin is missing a feature or has a defect, you can fill a feature request or bug report in our issue tracker. When creating a new issue, please provide a comprehensive description of your concern. Especially for fixing bugs it is crucial that the developers can reproduce your problem. For this reason, entire debug logs, POMs or most preferably little demo projects attached to the issue are very much appreciated. Of course, patches are welcome, too. Contributors can check out the project from our source repository and will find supplementary information in the guide to helping with Maven.

Goals

Plugin Documentation

Goals available for this plugin:

Goal Description
war:exploded Create an exploded webapp in a specified directory.
war:help Display help information on maven-war-plugin. Call mvn war:help -Ddetail=true -Dgoal= to display parameter details.
war:inplace Generate the webapp in the WAR source directory.
war:war Build a WAR file.

System Requirements

The following specifies the minimum requirements to run this Maven plugin:

Maven 3.1.0
JDK 1.7
Memory No minimum requirement.
Disk Space No minimum requirement.

Usage

用法

You should specify the version in your project’s plugin configuration:

您应该明确指定项目中所使用插件的版本

<project>...<build><!-- To define the plugin version in your parent POM --><pluginManagement><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><version>3.3.2</version></plugin>...</plugins></pluginManagement><!-- To use the plugin goals in your POM or parent POM --><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><version>3.3.2</version></plugin>...</plugins></build>...
</project>

For more information, see “Guide to Configuring Plug-ins”

Usage

Usage

There are 4 ways to use the WAR Plugin:

  • using the package phase with the project package type as war

  • 当项目的打包方式为war包时,使用package阶段

  • invocation of the war:war goal

  • 调用war:war目标

  • invocation of the war:exploded goal

  • 调用war:exploded目标

  • invocation of the war:inplace goal

  • 调用war:inplace目标

Note: When using the war: goals it is assumed that the compile phase is already done. The WAR Plugin is not responsible for compiling the java sources or copying the resources.

注意:当使用war:目标时,假设compile阶段已经完成,war插件不负责编译源代码或者复制resources资源

To handle archiving this version of Maven WAR Plugin uses Maven Archiver 3.5.0.

To handle filtering this version of Maven WAR Plugin uses Maven Filtering 3.1.1.

Using the package phase with the project package type as war / invocation of the war:war goal

当项目的打包方式为war包时使用package阶段/调用war:war目标

This is the normal way of using the WAR Plugin. To illustrate, here’s the pom.xml for our project:

这是war插件的一般使用方式,为了说明,这是我们项目的pom文件

<project>...<groupId>com.example.projects</groupId><artifactId>documentedproject</artifactId><packaging>war</packaging><version>1.0-SNAPSHOT</version><name>Documented Project</name><url>http://example.com</url>...
</project>

The project’s structure looks like this:

项目结构如下

 |-- pom.xml`-- src`-- main|-- java|   `-- com|       `-- example|           `-- projects|               `-- SampleAction.java|-- resources|   `-- images|       `-- sampleimage.jpg`-- webapp|-- WEB-INF|   `-- web.xml|-- index.jsp`-- jsp`-- websource.jsp

Invoking

mvn package

or

mvn compile war:war

will generate the WAR file target/documentedproject-1.0-SNAPSHOT.war. Here are the contents of that WAR file:

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|-- index.jsp`-- jsp`-- websource.jsp

Invocation of war:exploded goal

To speed up testing during the developement phase, war:explode can be used to generate the WAR in exploded form. Use the same project as above and invoke:

mvn compile war:exploded

This will generate an exploded version of the WAR in target/documentedproject-1.0-SNAPSHOT. The contents of that directory looks like this:

 documentedproject-1.0-SNAPSHOT|-- META-INF|-- WEB-INF|   |-- classes|   |   |-- com|   |   |   `-- example|   |   |       `-- projects|   |   |           `-- SampleAction.class|   |   `-- images|   |       `-- sampleimage.jpg|   `-- web.xml|-- index.jsp`-- jsp`-- websource.jsp

The default directory for the exploded WAR is target/<finalName>. The finalName is usually in the form of <artifactId>-<version>. This default directory can be overridden by specifying the webappDirectory parameter.

解包的war默认的目录是 target/,finalName通常采用-的形式,可以通过指定webappDirectory参数来覆盖此默认目录

<project>...<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><version>3.3.2</version><configuration><webappDirectory>/sample/servlet/container/deploy/directory</webappDirectory></configuration></plugin></plugins></build>...
</project>

Invocation of war:inplace goal

Another variation of war:exploded is war:inplace. With war:inplace the exploded WAR is created in the webapp source, which defaults to src/main/webapp. Use our sample project above, and invoke:

mvn compile war:inplace

This will result in:

 |-- pom.xml|-- src|   `-- main|       |-- java|       |   `-- com|       |       `-- example|       |           `-- projects|       |               `-- SampleAction.java|       |-- resources|       |   `-- images|       |       `-- sampleimage.jpg|       `-- webapp|           |-- META-INF|           |-- WEB-INF|           |   |-- classes|           |   |   |-- com|           |   |   |   `-- example|           |   |   |       `-- projects|           |   |   |           `-- SampleAction.class|           |   |   `-- images|           |   |       `-- sampleimage.jpg|           |   `-- web.xml|           |-- index.jsp|           `-- jsp|               `-- websource.jsp`-- target`-- classes|-- com|   `-- example|       `-- projects|           `-- SampleAction.class`-- images`-- sampleimage.jpg

Configuration

Overlays

Overlays

Overlays are used to share common resources across multiple web applications. The dependencies of a WAR project are collected in WEB-INF/lib, except for WAR artifacts which are overlayed on the WAR project itself.

overlays用于跨多个web应用共享公共资源。除了要在war项目本身做叠加的组件,其它的依赖会被收集在WEB-INF/lib目录下

Overlays at a glance

To demonstrate, given this structure for the project documentedproject:

为了做演示,给出项目documentedproject的格式

 |-- pom.xml`-- src`-- main|-- java|   `-- com|       `-- example|           `-- projects|               `-- SampleAction.java|-- resources|   |-- images|   |   `-- sampleimage.jpg|   `-- sampleresource`-- webapp|-- WEB-INF|   `-- web.xml|-- index.jsp`-- jsp`-- websource.jsp

The project depends on another WAR artifact, documentedprojectdependency-1.0-SNAPSHOT.war, which is declared as a dependency in the project’s pom.xml:

项目依赖另一个war组件,documentedprojectdependency-1.0-SNAPSHOT.war,这个组件在pom.xml文件中,会被声明为一个dependency依赖

<project>...<dependencies><dependency><groupId>com.example.projects</groupId><artifactId>documentedprojectdependency</artifactId><version>1.0-SNAPSHOT</version><type>war</type><scope>runtime</scope></dependency>...</dependencies>...
</project>

The structure for the documentedprojectdependency WAR file looks like this:

documentedprojectdependency组件的结构如下

documentedprojectdependency-1.0-SNAPSHOT.war|-- META-INF|   |-- MANIFEST.MF|   `-- maven|       `-- com.example.projects|           `-- documentedprojectdependency|               |-- pom.properties|               `-- pom.xml|-- WEB-INF|   |-- classes|   |   |-- com|   |   |   `-- example|   |   |       `-- projects|   |   |           `-- SampleActionDependency.class|   |   `-- images|   |       `-- sampleimage-dependency.jpg|   `-- web.xml`-- index-dependency.jsp

The resulting WAR would end up like this:

 |-- META-INF|   |-- MANIFEST.MF|   `-- maven|       `-- com.example.projects|           `-- documentedproject|               |-- pom.properties|               `-- pom.xml|-- WEB-INF|   |-- classes|   |   |-- com|   |   |   `-- example|   |   |       `-- projects|   |   |           |-- SampleAction.class|   |   |           `-- SampleActionDependency.class|   |   `-- images|   |       |-- sampleimage-dependency.jpg|   |       `-- sampleimage.jpg|   `-- web.xml|-- index-dependency.jsp|-- index.jsp`-- jsp`-- websource.jsp

The web.xml file above comes from documentedproject.

上面的web.xml文件来自documentedproject

Overlay types

The WAR Plugin handles both war and zip artifacts as overlays. However, for backward compatibility reasons, zip overlays are handled only if they are defined explicitly in the plugin’s configuration.

war插件可以对wer或者zip组件做覆盖处理。然而,出于向后兼容的原因,只有在插件配置中明确指明了才会进行zip覆盖处理

Configuring Overlays

In previous versions of the WAR Plugin, no configuration was necessary. This is still the case if you are happy with the default settings. However, if you need more control, read on!

在插件的以前版本中,没有一个配置是必须的。如果默认配置感到满意,现在也仍是这样。然而,如果您需要更多的控制,请继续阅读

The element can have the following child elements:

overlay节点可以包含以下的子节点

  • id - the id of the overlay. If none is provided, the WAR Plugin will generate one.

  • id - overlay的id,如果没有,war插件将会生成一个。

  • groupId - the groupId of the overlay artifact you want to configure.

  • groupld - 想要配置的叠加组件的groupId

  • artifactId - the artifactId of the overlay artifact you want to configure.

  • artifactId - 想要配置的叠加组件的artifactId

  • type - the type of the overlay artifact you want to configure. Default value is: war.

  • type - 想要配置的叠加组件的type,默认是:war

  • classifier - the classifier of the overlay artifact you want to configure if multiple artifacts matches the groupId/artifactId.

  • classifier - 想要配置的叠加组件的classifier,如果多个组件匹配groupId/artifactId

  • includes - the files to include. By default, all files are included.

  • 要包含的文件,默认会包含所有文件

  • excludes - the files to exclude. By default, the META-INF/MANIFEST.MF file is excluded.

  • 要排除的文件,默认META-INF/MANIFEST.MF文件会被排除

  • targetPath - the target relative path in the webapp structure, which is only available for overlays of type war. By default, the content of the overlay is added in the root structure of the webapp.

  • targetPath - 目标在webapp结构中的相对路径,仅适用于war类型的覆盖。默认叠加的内容会被添加到webapp结构的根路径

  • skip - set to true to skip this overlay. Default value is: false.

  • skip - 设置为true可以跳过这个overlay,默认值为:false

  • filtered - whether to apply filtering to this overlay. Default value is false.

  • 是否对这个overlay进行过滤,默认值为:false

For instance, to exclude the sampleimage-dependency.jpg of our documentedprojectdependency war overlay above:

例如,叠加documentedprojectdependency.war组件并排除其中的sampleimage-dependency.jpg文件

<project>...<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><version>3.3.2</version><configuration><overlays><overlay><groupId>com.example.projects</groupId><artifactId>documentedprojectdependency</artifactId><excludes><exclude>WEB-INF/classes/images/sampleimage-dependency.jpg</exclude></excludes></overlay></overlays></configuration></plugin></plugins></build>...
</project>

Overlays packaging

Overlays are applied with a first-win strategy (hence if a file has been copied by one overlay, it won’t be copied by another). Overlays are applied in the order in which they are defined in the configuration. If no configuration is provided, the order in which the dependencies are defined in the POM is used (warning: this is not deterministic, especially if you have overlays as transitive dependencies). In case of a mixed situation (e.g. configured overlays and non-configured overlays), non-configured overlays are applied after configured overlays.

叠加采用的是先赢策略(因此,如果一个文件被复制从一个叠加组件复制过来,就不会再从其它组件复制了),按照在overlays配置中定义的顺序进行加载。如果未提供相关的配置,加载的顺序为该依赖在pom文件中被应用的顺序(警告:这是不确定的,尤其当叠加为传递依赖时)。在混合情况下(例如,有配置的叠加和无配置的叠加),先加载有配置的叠加,再加载无配置的叠加

By default, the source of the project (a.k.a the current build) is added first (e.g. before any overlay is applied). The current build is defined as a special overlay with no groupId, artifactId. If overlays need to be applied first, simply configure the current build after those overlays.

默认情况下,项目的源代码(也就是当前构建的项目)会被优先加载(例如,在任何的叠加被加载之前),当前构建的项目被定义为一个没有groupId和artifactId的特殊的叠加,如果有一些叠加需要被首先应用,只需要配置当前构建的项目在这些叠加之后。

For instance, if my-webapp from the com.example.projects group is a dependency of the project and needs to be applied before the project’s own source, do as follows:

举例,如果项目的一个依赖my-webapp,com.example.proects需要在项目自己的源代码之前被应用,请执行以下操作:

<project>...<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><version>3.3.2</version><configuration><overlays><overlay><groupId>com.example.projects</groupId><artifactId>my-webapp</artifactId></overlay><overlay><!-- empty groupId/artifactId represents the current build --></overlay></overlays></configuration></plugin></plugins></build>...
</project>

Note: In the scenario above, any other WAR dependency will be applied after the current build since they have not been configured in the <overlays> element.

注意:在上面的场景中,任何其他WAR依赖项都将在当前构建之后应用,因为它们尚未在<overlays>元素中配置。

To perform an even more fine grained overwriting policy, overlays can be packaged multiple times with different includes/excludes. For instance if the index.jsp file of the overlay my-webapp must be set in the webapp but other files can be controlled the regular way, define two overlay configurations for my-webapp:

为了执行更细粒度的覆盖策略,可以使用不同的包含/排除对叠加进行多次打包。例如,如果my-webapp中的index.jsp文件必须设置在webapp中,但其他文件可以用常规的方式控制,可以为my-webapp定义两个叠加配置:

<project>...<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><version>3.3.2</version><configuration><overlays><overlay><id>my-webapp-index.jsp</id><groupId>com.example.projects</groupId><artifactId>my-webapp</artifactId><includes><include>index.jsp</include></includes></overlay><overlay><!-- empty groupId/artifactId represents the current build --></overlay><!-- Other overlays here if necessary --><overlay><id>my-webapp</id><groupId>com.example.projects</groupId><artifactId>my-webapp</artifactId></overlay></overlays></configuration></plugin></plugins></build>...
</project>

Overlay global settings

The following settings can be specified globally and modify the way all overlays are applied.

下面的配置是全局配置,修改会对所有的叠加应用

  • dependentWarIncludes - sets the default includes to apply to all overlays. Any overlay that has no specific includes element will inherit this setting by default.

  • dependentWarIncludes - 对所有的叠加设置默认的包含目录。默认情况下,任何没有指定includes元素的叠加都将继承此设置。

    <project>...<plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><version>3.3.2</version><configuration><dependentWarIncludes>**/IncludeME,**/images</dependentWarIncludes></configuration></plugin></plugins>...
    </project>
    
  • dependentWarExcludes - sets the default excludes to apply to all overlays. Any overlay that has no specific excludes element will inherit this setting by default.

  • dependentWarExcludes - 对所有的叠加设置默认的排除目录。默认情况下,任何没有指定excludes元素的叠加都将继承此设置。

    <project>...<plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><version>3.3.2</version><configuration><dependentWarExcludes>WEB-INF/web.xml,index.*</dependentWarExcludes></configuration></plugin></plugins>...
    </project>
    
  • workDirectory - sets the directory where overlays will be temporarily extracted.

  • workDirectory - 设置临时提取叠加的目录

    <project>...<plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><version>3.3.2</version><configuration><!-- default value is target/war/work --><workDirectory>/tmp/extract_here</workDirectory></configuration></plugin></plugins>...
    </project>
    

Zip dependencies with overlays

To use a zip dependency as an overlay you have to configure it explicitly in the plugin’s configuration. For instance to inject the content of a zip overlay in the scripts directory of the webapp, do as follows:

要使用zip依赖作为叠加,您必须在插件的配置中明确配置它。例如,要在webapp的scripts目录中添加一个zip叠加的内容,请执行以下操作:

<project>...<plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><version>3.3.2</version><configuration><overlays><overlay><groupId>zipGroupId</groupId><artifactId>zipArtifactId</artifactId><type>zip</type><targetPath>scripts</targetPath></overlay></overlays></configuration></plugin></plugins>...
</project>

maven-war-plugin插件 overlays maven-war-plugin翻译相关推荐

  1. 【maven详解-插件】maven插件学习之maven-source-plugin

    在pom.xml文件build节点下加入以下代码: 1 <plugin> 2 <groupId>org.apache.maven.plugins</groupId> ...

  2. 内置在maven项目的服务器,IDEA使用maven中tomcat插件来启动服务器配置

    一 .在项目pom文件中配置tomcat 先添加如下配置: org.apache.maven.plugins maven-compiler-plugin 2.3.2 1.7 1.7 org.apach ...

  3. Gradle 自定义Plugin插件之发送钉钉通知

    在之前的文章中,我们介绍了怎么使用Gradle插件,apk加固,上传到蒲公英. 这篇文章,主要就是把流程进一步完善,通过Gradle插件实现:打包-加固-上传蒲公英-发送钉钉消息,实现完全自动化.. ...

  4. 安装plugin插件

    前提grails必须安装好 安装好之后运行出错 安装plugin插件 进入catweb3.2/plugin/grails-remoting文件 输入命令:grails,如图所示安装中 之后出现黄色加粗 ...

  5. jenkins基于Role Strategy Plugin插件的权限管理设置

    由于jenkins默认的权限管理体系不支持用户组或角色的配置,因此需要安装第三发插件来支持角色的配置,本文将使用Role Strategy Plugin插件. Role Strategy Plugin ...

  6. maven生成html单元测试报告,Maven中配置生成单元测试报告配置

    对junit单元测试的报告: 1.  ------------------------------------------------------- 2.   T E S T S 3.  ------ ...

  7. maven插件_Apache Maven WAR Plugin_用overlays合并多个war

    转: http://kyfxbl.iteye.com/blog/1678121 在一个大项目中拆分maven工程时,很有可能会把js.css.jsp等文件放在不同的工程里(根据业务模块划分).因为如果 ...

  8. 利用Maven的War Overlays实现War包资源共享

    Maven War plugin提供了overlays功能,overlays提供了多个web应用程序共享资源的途径.通过overlays,可以通过包依赖实现个性化定制开发,而不是直接在已有成熟软件的源 ...

  9. YUI Compressor插件压缩后war中的js/css文件未压缩的解决方法(被maven打包顶替了)

    YUI Compressor Maven插件可以压缩/合并js或css文件,经常用在Maven项目中,但最近发现在wabapp中执行了 mvn install 命令进行发布之后,终端中显示插件已经执行 ...

  10. java war包合并,使用maven warpath插件合并多module的war包

    查看原文:http://www.yeetrack.com/?p=899 现在java 项目一般使用maven.gradle等工具来管理jar包.打包.发布.如果一个项目有很多模块,那般是分成多个mod ...

最新文章

  1. 海康威视人证对比设备SDK-C#
  2. linux查看内存、cpu等硬件信息
  3. Drupal的高速缓存配置APC
  4. 计算机是如何按照时钟来顺序工作的
  5. print输出字体特效
  6. Python3NumPy——数组(2)之数学空间与NumPy空间
  7. python安装numba_python – 在OS X上安装Numba时出错
  8. iOS万能跳转界面的方法
  9. linux 命令终端显示-bash-4.2#解决方法
  10. 关于 SENDKEYS 的代码
  11. Web——Request转发和Response重定向
  12. 一键抠除路人甲,昇腾CANN带你识破神秘的“AI消除术”
  13. 数据结构 3-2-2 队列的顺序存储实现
  14. 配置多个git账号_Git ssh配置(Mac)
  15. spark源码阅读之network(2)
  16. 利用workbench建立的响应面模型质量很差,该如何解决?求指点
  17. Design Tradeoffs for SSD Performance
  18. c++项目开发——吃豆子游戏
  19. Boost电路硬件设计实例
  20. python构造自定义数据包_Python发送网络封包,自定义封包结构与内容并发出去

热门文章

  1. 高德地图Android自定义路线规划的简单实现
  2. 70后游戏辅助开发程序猿的人生路(二)
  3. php pcntl fork使用,php中pcntl_fork详解
  4. php红包互助源码_分享朋友圈奖红包的微擎应用源码 php版 v2.0
  5. 《安富莱嵌入式周报》第272期:2022.06.27--2022.07.03
  6. SAP ABAP 使用内存参数设置SET /GET PARAMTER ID
  7. 纯文本还是HTML邮件
  8. 企业电子邮箱注册哪个好?如何注册电子邮箱?
  9. ARouter 源码分析
  10. 单片机入门(实现流水灯)--适合初学者