In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to use springboot packaging plug-in to remove jar package weight loss" related knowledge, editor through the actual case to show you the operation process, the method of operation is simple and fast, practical, I hope that this "how to use springboot packaging plug-in to remove jar package weight loss" article can help you solve the problem.
1. Pom file configuration 1.1 add the maven-dependency-plugin plug-in to copy the referenced jar package to the specified path
It is convenient to specify the dependent package path for subsequent tomcat startup.
Org.apache.maven.plugins maven-dependency-plugin copy package copy-dependencies ${project.build.directory} / lib
The directory structure built with this plug-in has an additional lib directory (that is, the path specified by the outputDirectory in the above configuration), which contains the dependent jar package:
1.2 the springboot project uses the spring-boot-maven-plugin package plug-in org.springframework.boot spring-boot-maven-plugin true ZIP com.iasp.BasicStarter ${groupId} ${artifactId} Repackage
After configuring the above package, the corresponding jar package is excluded, making the size of the Flat jar package made by the plug-in smaller, making it easy for the upload server to publish. The effect is as follows: the lib directory under the BOOT-INF directory is gone:
The structure in the original jar package is
Then specify the jar package path-Dloader.path= ".. / lib" when starting the project, so that you can achieve the slimming effect, which depends on placing it in the D:develop/shared/fjar directory and executing the run command.
Java-Dloader.path= "D:develop/shared/fjar"-jar mytest.jar
Note: another startup scheme is to specify the path without adding-Dloader.path= "D:develop/shared/fjar" and start it directly with the following instructions
Java-jar mytest.jar
To use the above startup, you need to add the maven-jar-plugin plug-in and configure the properties. In addition, when processing some files in the read executable jar, you can use the maven-jar-plugin plug-in to replace spring-boot-maven-plugin for packaging operation.
Org.apache.maven.plugins maven-jar-plugin true lib/ com.common.util.CommonUtilsApplication
The above plug-in effect is to add Class-path corresponding to jar in the MANIFEST.MF file in the meta _ INF directory of the package, so that when the later application is launched, it will only load the required version dependencies according to Class-Path (solving the problem of multiple version load reference conflicts in the shared directory), this effect is equivalent to adding the parameter-classpath xxx (specific jar).
At this point, you can put the required jar directory lib in the same directory as the xxx.jar you want to run, and you can start without adding the-Dloader.path parameter. If the lib directory and the xxx.jar to be run are not in the same directory, you need to use-Dloader.path to start.
As follows: start in the same level directory
Do not start in the same level directory:
Among them,-Dloader.path can specify multiple directories, so that some publicly used jar can be placed in a shared directory when there are multiple micro-services, and the jar unique to each micro-service can be placed in a private directory of micro-services (to solve the problem of jar version conflicts). Examples are as follows:
Note:
1. To use-Dloader.path, you need to add ZIP when packaging. If not specified, Dloader.path will not take effect.
It is recommended to use maven-jar-plugin packaging for slimming packaging of multiple micro-services to avoid some application startup problems caused by spring-boot-maven-plugin packaging mechanism (already stepped on)
2. If there are different version dependencies:
For example, if project A relies on version 1.0 of Y library and project B depends on version 2.0 of Y library, there may be version dependency conflicts (if the two versions are not compatible), and the solution:
2.1, if you can achieve the same version, keep using the same version, and ensure that the version is consistent. You can use maven's version dependency management to handle it, that is, to use unified management of dependent versions in the parent pom file
2.2. let the project rely on the required version and enter it into the war package, and 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 following figure, the comm-0.0.1.jar version is used.
Note:
With the spring-boot-maven-plugin plug-in, all dependent jar packages are packaged so that the generated JAR packages can be run directly, simplifying our development operations.
Using the spring-boot-maven-plugin plug-in defaults to Main-Class: org.springframework.boot.loader.JarLauncher if you do not specify the main run entry class of the program
This can be customized to execute the main entry class There are the following ways: if 1.POM inherits spring-boot-starter-parent org.springframework.boot spring-boot-starter-parent 2.1.9.RELEASE ccom.notes.JavaNotesApplication2.POM instead of inheriting spring-boot-starter-parent, you need to specify org.springframework.boot spring-boot-maven-plugin 2.1.9.RELEASE com.notes.JavaNotesApplication ZIP Repackage 3.POM does not inherit spring-boot-starter-paren And use the maven-jar-plugin plug-in to specify the executing class org.springframework.boot spring-boot-maven-plugin org.apache.maven.plugins maven-jar-plugin true false lib/ com.notes.JavaNotesApplication ${project.version} about how to use So much for the springboot package plug-in to remove the slimming of the jar package. Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.