maven usage

2 篇文章 0 订阅

Usage

There are 4 ways to use the WAR Plugin:

  • using the package phase with the project package type as war
  • invocation of the war:war goal
  • invocation of the war:exploded goal
  • invocation of the war:inplace goal

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.

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

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

 
  1. <project>
  2. ...
  3. <groupId>com.example.projects</groupId>
  4. <artifactId>documentedproject</artifactId>
  5. <packaging>war</packaging>
  6. <version>1.0-SNAPSHOT</version>
  7. <name>Documented Project</name>
  8. <url>http://example.com</url>
  9. ...
  10. </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.

 
  1. <project>
  2. ...
  3. <build>
  4. <plugins>
  5. <plugin>
  6. <groupId>org.apache.maven.plugins</groupId>
  7. <artifactId>maven-war-plugin</artifactId>
  8. <version>3.3.1</version>
  9. <configuration>
  10. <webappDirectory>/sample/servlet/container/deploy/directory</webappDirectory>
  11. </configuration>
  12. </plugin>
  13. </plugins>
  14. </build>
  15. ...
  16. </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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值