Use Maven war package to package and remove jar package to reduce weight


1. POM file configuration

1.1 add Maven dependency plugin to copy the referenced jar package to the specified path

It is convenient to specify the dependent package path for subsequent Tomcat startup

<!-- Copy the dependency to the Lib directory outside the jar -- >
            <configuration>                <!-- Specified dependency path -- >

After using this plug-in to build the directory structure, there is an additional lib directory (i.e. the path specified in the outputdirectory configured above), which is the dependent jar package:

1.2 add Maven war plugin

<!--  War package -- >
            <!-- Exclude specific jar packages -- >
            <!-- Exclude all jar packages that do not start with Commons -- >
            <!-- Exclude all jar packages starting with Commons -- >

The war package printed after the above configuration will remove the corresponding jar package under / WEB-INF / lib / in the war package, so as to reduce the size of the release package and speed up the upload server. As shown in the figure below, pressurize the war package and check the WEB-INF / lib directory. There is no jar package beginning with commons, which indicates that it has been removed:

The original war package contains many jars starting with commons, as shown in the following figure:

According to the above ideas, we can remove all jars under lib. After removing the dependent jars, we can configure themTomcat refers to the external lib pathTo deploy the project

note appended:

If there are different version dependencies: for example, project a depends on version 1.0 of Library y, and project B depends on version 2.0 of Library y, version dependency conflicts may occur (when the two versions are incompatible)


1. Keep the same version if you can keep the same version, and try to ensure that multiple projects use the same version of the same library

2. Let each project depend on the required version and put it into the war package. Put other jar packages of the same version under the same shared package

The test found that the dependency is found from top to bottom when searching, and the first one is used when matching

As shown in the figure below, comm-0.0.1 will be used Jar version

Spring boot packaging plug-in removes jar package and slims down

The above is my personal experience. I hope I can give you a reference, and I hope you can support developpaer.

Recommended Today

Implementation example of adding permissions with laravel and Vue

catalogue 1、 Add (permission) node 1.1 introduction of Vue 1.2. Add templates (Vue, jQuery) 1.3. Add node controller logic 1.4. Define modifiers in the model 1.5. Effect: 1、 Add (permission) node 1.1 introduction of Vue usevueManage the interface and realize the addition functionWe put it in this directoryvue.js: 1.2. Add templates (Vue, jQuery) resources/admin/node/create.blade.php: <!–_ […]