In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you what to pay attention to the use of springboot maven packaging plug-ins, I hope you will gain something after reading this article, let's discuss it together!
1. The executable jar generated by the springboot project by default, why can't it be imported as a dependency to other projects?
The default plug-in for the Spring Boot project is spring-boot-maven-plugin:
Org.springframework.boot spring-boot-maven-plugin
Using the above plug-in packages Project An into an executable jar and an .original file as follows:
As you can see, the executable jar package is much larger than another original file. Extract the two files separately, and the original file can be decompressed by removing the suffix and renaming: the executable jar can be opened as follows:
After renaming the original file, open as follows:
From the comparison of these two pictures, we can see that the executable jar puts the dependencies of the project into it, and the directory is different from the traditional jar package directory, with an extra layer of BOOT-INF, so this jar package cannot be directly used as a dependency for other projects. The non-executable jar does not type the dependency into it, which is consistent with the traditional jar package directory, so removing its .original suffix can be used as a dependency for other projects.
two。 Is there a way to get executable jar and rely on jar at once?
Of course, officials are ready to use the following plug-ins:
Org.springframework.boot spring-boot-maven-plugin exec
Packaging result:
Problems encountered
When the dependency jar of the above A project is introduced into another project B, the startup project still cannot find the relevant dependency?
Reason:
Because the above dependency jar does not bring in other jar packages that Project A depends on, it just types the code of Project An into jar packages.
Solution:
Install the above A project dependency jar to the local maven warehouse or the company's private server, and then introduce it through maven in Project B, because through the introduction of maven, the project will automatically find the dependencies that need to be introduced by relying on jar itself. (recommended) put the above A project dependency jar directly under the B project project, that is, springboot introduces the third-party jar. After this introduction, you also need to separately introduce the dependencies used in the A project in the pom file of the B project. Using the following packaging plug-in, when typing the dependency jar of Project A, type all the dependencies needed by Project A together.
Put all dependencies in the project into a packaged plug-in that relies on jar
Maven-assembly-plugin false jar-with-dependencies com.libii.sso.LibiiSpringBootStartApplication make-assembly package single
Packaging result:
Springboot Packaging plug-in details (spring-boot-maven-plugin) introduction configuration after adding org.springframework.boot spring-boot-maven-plugin, you can see the Plugins section in the Maven toolbar
Build-info: build the project's build information file build-info.properties
Repackage: this is the default goal. After mvn package is executed, this command is packaged again to generate an executable jar, while renaming the jar generated by mvn package to * .origin
Run: this can be used to run Spring Boot applications
Start: during the mvn integration-test phase, the Spring Boot application life cycle is managed.
Stop: during the mvn integration-test phase, the Spring Boot application life cycle is managed.
Take a look at the configuration of the packaged plug-in in the pom.xml of the SpringBoot parent project
It is found that the parent project specifies repackage [spring-boot-starter-parent pom.xml]
Org.springframework.boot spring-boot-maven-plugin repackage ${start-class}
Let's take a look at the MANIFEST.MF in the package result.
Manifest-Version: 1.0
Implementation-Title: first-spring-boot-application
Implementation-Version: 1.0.0-SNAPSHOT
Built-By: weifei
Implementation-Vendor-Id: thinking-in-spring-boot
Spring-Boot-Version: 2.0.2.RELEASE
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: thinking.in.spring.boot.App
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Created-By: Apache Maven 3.5.2
Build-Jdk: 1.8.0_172-ea
Implementation-URL: http://maven.apache.org
It is found that the Main-Class attribute value is org.springframework.boot.loader.JarLauncher.
This value can control org.springframework.boot spring-boot-maven-plugin ZIP com.common.util.CommonUtilsApplication repackage by setting the property layout.
Set Main-Class to org.springframework.boot.loader.PropertiesLauncher when setting ZIP
The specific layout values correspond to the Main-Class relations as follows
1.JAR, the usual executable jar
Main-Class: org.springframework.boot.loader.JarLauncher
2.WAR, the usual executable war, requires servlet containers that depend on the WEB-INF/lib-provided
Main-Class: org.springframework.boot.loader.warLauncher
3.ZIP, or DIR, is similar to JAR
Main-Class: org.springframework.boot.loader.PropertiesLauncher
4.MODULE, packaging all dependent libraries (except those whose scope is provided), but not any Launcher of Spring Boot
5.NONE, packages all dependent libraries but does not package Spring Boot. The reason why any Launcher can be run using java-jar is closely related to the configuration in the MANIFEST.MF file.
Give away knowledge points:
Generally speaking, it is not recommended to reference an executable jar typed using the spring-boot-maven-plugin plug-in as a jar to other services, because there may be problems that cannot be found in some configuration files in the access executable jar.
If you want the original built jar (no plug-in-related packages and no changes to the MANIFEST.MF) not to be repackaged (repackaging introduces spring-boot-maven-plugin customized configuration and jar packages), you can configure the classifier property on the spring-boot-maven-plugin plug-in to customize a runnable jar name so that the plug-in does not rename the original jar.
After reading this article, I believe you have a certain understanding of "what are the considerations for using springboot maven packaging plug-ins". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for your reading!
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.