Introduction to maven maven war plugin

Time:2020-5-10

Use background

Recently, the project uses nodejs + webpack as the front-end construction, Tomcat as the web container. When packaging, you want to exclude or only print the built front-end files. Here, you use Maven war plugin to do some configuration to realize the filtering and increase of resources when you play the war package. Next, you will introduce the specific configuration and use

Plug in use

Plug in official website

https://maven.apache.org/plug…

Common use cases can be seen

  • Add and filter web resources
  • Add or filter unnecessary jar packages
  • War mainfest file generation

Practical introduction

The common use cases above are all in English. Don’t worry about the poor English. There are a large number of configurations in them. You can only choose what you can read and combine with the project. I only use the web resources to add and filter. So in the actual war, I only introduce this kind of case. There is no other operation, so I dare not make any assertion.

First post my project structure
–pom.xml
–src
—-main
——Front (front end resource)
——–Build (built page)
——–* (build related scripts)
——java
——resources
——webapp
——–WEB-INF
—-test

Target: when packing, type the page in front / build into webapp. The configuration in POM is as follows

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                        </manifest>
                    </archive>
                    <webResources>
                        <resource>
                            <directory>src/main/front/build</directory>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
        </plugins>
    </build>

The directory directory is relative to pom.xml

Packed catalog

Introduction to maven maven war plugin

Manifest.mf (with the dependent classpath entered)

Manifest-Version: 1.0
Built-By: hzq
Class-Path: common-model-1.0.1-20160504.035104-4.jar delivery-service-
 1.0-SNAPSHOT.jar delivery-common-1.0-SNAPSHOT.jar commons-lang3-3.4.j
 ar commons-io-2.4.jar commons-fileupload-1.3.1.jar slf4j-api-1.7.21.j
 ar logback-classic-1.1.7.jar logback-core-1.1.7.jar logback-access-1.
 1.7.jar fastjson-1.2.7.jar delivery-api-1.1.1-RELEASE.jar lombok-1.16
 .4.jar spring-core-4.2.5.RELEASE.jar commons-logging-1.1.1.jar spring
 -beans-4.2.5.RELEASE.jar spring-jdbc-4.2.5.RELEASE.jar spring-tx-4.2.
 5.RELEASE.jar spring-context-4.2.5.RELEASE.jar spring-aop-4.2.5.RELEA
 SE.jar aopalliance-1.0.jar spring-test-4.2.5.RELEASE.jar spring-webmv
 c-4.2.5.RELEASE.jar spring-expression-4.2.5.RELEASE.jar spring-web-4.
 2.5.RELEASE.jar javax.servlet-api-3.1.0.jar jstl-1.2.jar
Created-By: IntelliJ IDEA
Build-Jdk: 1.8.0_40

OK, the goal has been achieved. End of work! If you want to know more about other configurations, you can take a look at the common cases on the official website, which are listed above.