In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to deploy Jar files in SpringBoot". In daily operation, I believe many people have doubts about how to deploy Jar files in SpringBoot. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "how to deploy Jar files in SpringBoot". Next, please follow the editor to study!
Main configuration:
${project.artifactId} org.springframework.boot spring-boot-maven-plugin
Configuration output:
Cd package-optimize-level0mvn clean installls-lh package-optimize-app1/target/package-optimize-app1.jar-rw-r--r-- 1 lixia wheel 16m Feb 24 21:06 package-optimize-app1/target/package-optimize-app1.jarjava-jar package-optimize-app1/target/package-optimize-app1.jar
Key notes:
(the current demo application relies on only a few spring-boot-starter-web components, and all build outputs are only about a dozen MB.) in fact, the output jar of a single build ranges from dozens of MB to one or two hundred MB or more according to the number of dependent components of the project.
If there are a dozen or so microservices to deploy, that means you need to transfer one or two GB files, which can take a lot of time to imagine. Even individual microservices for a single update need to transmit one or two hundred MB.
Level 1: a common build method that relies on jar separation
Reference project directory: package-optimize-level1
Close to solve the problem:
Reduce the file size of a single micro-service jar so that the deployment process can transfer files in seconds. Main configuration:
For more information on key configuration, please see the following notes:
${project.artifactId} org.apache.maven.plugins maven-dependency-plugin copy-dependencies package copy-dependencies ${project.build.directory} / lib false false true org.springframework.boot spring-boot-maven-plugin Null null ZIP repackage
Configuration output:
Cd package-optimize-level1mvn clean installls-lh package-optimize-app1/target/package-optimize-app1.jar-rw-r--r-- 1 lixia wheel 149K Feb 24 20:56 package-optimize-app1/target/package-optimize-app1.jarjava-jar- Djava.ext.dirs=lib package-optimize-app1/target/package-optimize-app1.jar
Achieve results:
The output jar of a single build based on the number of components dependent on the project is generally only one or two hundred KB, which can basically be transmitted in seconds.
This is the most common optimization seen online, and it's worth delving further: if you have a dozen or so microservices, each with a jar and a lib directory file, the first deployment requires almost one or two GB files to be transferred.
Level 2: merge all modules that depend on jar into the same lib directory
Reference project directory: package-optimize-level2
Resolve the problem:
Merging all modules depends on jar to the same lib directory. Generally, because each module project relies on jar to overlap, the total size of merging all service deployment files is basically two to three hundred MB.
However, if you use-Djava.ext.dirs=lib to load all the jar into each JVM, on the one hand, each JVM loads all the jar consumption resources completely, and on the other hand, the version conflict will occur with different versions of the micro-service components.
Main configuration:
For more information on key configuration, please see the following notes:
${project.artifactId} org.apache.maven.plugins maven-jar-plugin true lib/ false Org.apache.maven.plugins maven-dependency-plugin copy-dependencies package copy-dependencies ${boot-jar-output} / lib false org.springframework.boot Spring-boot-maven-plugin null null ZIP ${boot-jar -output} repackage
All lib directory files and microservices build jar aggregation into the devops public directory.
The Class-Path attribute based on the list of dependent components of the module is generated in the META-INFO/MANIFEST file in the microservice jar file, thus avoiding different versions of jar:
Class-Path: lib/spring-boot-starter-web-2.4.3.jar lib/spring-boot-starter- 2.4.3.jar lib/spring-boot-2.4.3.jar lib/spring-boot-autoconfigure-2.4 .3.jar lib/spring-boot-starter-logging-2.4.3.jar lib/logback-classic-1. 2.3.jar lib/logback-core-1.2.3.jar lib/slf4j-api-1.7.30.jar lib/log4j-t o-slf4j-2.13.3.jar lib/log4j-api-2.13.3.jar lib/jul-to-slf4j-1.7.30.jar lib/jakarta.annotation-api-1.3.5.jar lib/spring-core-5.3.4.jar lib/spring- jcl-5.3.4.jar lib/snakeyaml -1.27.jar lib/spring-boot-starter-json-2 .4.3.jar lib/jackson-databind-2.11.4.jar lib/jackson-annotations-2.11.4 .jar lib/jackson-core-2.11.4.jar lib/jackson-datatype-jdk8-2.11.4.jar lib/jackson-datatype- jsr310-2.11.4.jar lib/jackson-module-parameter-name s-2.11.4.jar lib/spring-boot-starter-tomcat -2.4.3.jar lib/tomcat-embed- core-9.0.43.jar lib/jakarta.el-3.0.3.jar lib/tomcat-embed-websocket-9.0 .43.jar lib/spring-web-5.3.4.jar lib/spring-beans-5.3.4.jar lib/spring- webmvc-5.3.4.jar lib/spring-aop-5.3.4.jar lib/spring-context-5.3.4.jar lib/spring-expression-5.3.4.jar
Configuration output:
Cd package-optimize-level2mvn clean installls-lh devops/total 912drwxr-xr-x 34 lixia wheel 1.1K Feb 24 22:27 lib-rw-r--r-- 1 lixia wheel 150K Feb 24 22:31 package-optimize-app1.jar-rw-r--r-- 1 lixia wheel 149K Feb 24 22:31 package-optimize-app2.jar-rw-r--r-- 1 lixia wheel 149K Feb 24 22:31 package-optimize-app3.jarjava-jar devops/package-optimize-app1.jar
Achieve results:
The-Djava.ext.dirs=lib parameter definition is no longer required for the startup process.
All microservices jar refer to the common directory of all project merge dependent components, and the total size of deployment files is generally two to three hundred megabytes.
By customizing the Class-Path in the META-INFO/MANIFEST file in each micro-service jar file to clearly indicate the dependent version component class, the conflict between different component versions of each micro-service can be solved.
Level 3: support for unofficial tripartite dependency components introduced by system
Reference project directory: package-optimize-level3
Resolve the problem:
Some unofficial tripartite such as sdk jar, one way is to submit it to the Maven local private server for reference, which is the same as relying on jar; but in the absence of maven private server, the common simplified approach is to place the dependency jar directly in the project and define it as system scope in pom.
For components introduced in pom as systemPath, the maven-jar-plugin component does not have a direct parameter to declare the components that contain the specified scope. Without special treatment, these scope-defined components will not appear in the META-INFO/MANIFEST, resulting in the runtime class cannot be found.
Main configuration:
For more information on key configuration, please see the following notes:
${project.artifactId} org.apache.maven.plugins maven-jar-plugin true lib/ false ${jar-manifestEntries-classpath} org.apache.maven.plugins maven-dependency-plugin copy-dependencies Package copy-dependencies ${boot-jar-output} / lib false false False org.springframework.boot spring-boot-maven-plugin null null ZIP ${boot-jar-output} repackage
The main configuration of the sub-module:
.. / devops. Lib/hik-sdk-1.0.0.jar com.hik hik-sdk 1.0.0 system ${project.basedir} / lib/hik-sdk-1.0.0.jar org.springframework.boot spring-boot-starter-web
The Class-Path attribute based on the list of dependent components of the module is generated in the META-INFO/MANIFEST file in the microservice output jar file, with the definition value of the jar-manifestEntries-classpath attribute appended first:
Class-Path:. Lib/hik-sdk-1.0.0.jar lib/spring-boot-starter-web-2.4.3.ja r lib/spring-boot-starter-2.4.3.jar lib/spring-boot-2.4.3.jar lib/spring-boot- autoconfigure-2.4.3.jar lib/spring-boot-starter-logging-2.4.3.ja r lib/logback-classic-1.2.3.jar lib/logback-core-1.2.3.jar lib / slf4j-ap i-1.7.30.jar lib/log4j-to-slf4j-2.13.3.jar lib/log4j-api-2.13.3.jar lib/ jul-to-slf4j-1.7.30.jar lib/jakarta.annotation-api-1.3.5.jar lib/spring- core-5.3.4.jar lib/spring-jcl-5.3.4.jar lib/snakeyaml-1.27.jar lib/spring- boot-starter-json-2. 4.3.jar lib/jackson-databind-2.11.4.jar lib/jackson- annotations-2.11.4.jar lib/jackson-core-2.11.4.jar lib/jackson-datatype- jdk8-2.11.4.jar lib/jackson-datatype-jsr310-2.11.4.jar lib/jackson- module-parameter-names-2.11.4.jar lib/spring-boot-starter-tomcat-2.4 .3.jar lib/tomcat-embed-core-9 .0.43.jar lib/jakarta.el-3.0.3.jar lib/to mcat-embed-websocket-9.0.43.jar lib/spring-web-5.3.4.jar lib/spring-bea ns-5.3.4.jar lib/spring-webmvc-5.3.4.jar lib/spring-aop-5.3.4.jar lib/spring- context-5.3.4.jar lib/spring-expression-5.3.4.jar
Configuration output:
Cd package-optimize-level3mvn clean installls-lh devops/total 912drwxr-xr-x 36 lixia wheel 1.1K Feb 24 23:14 lib-rw-r--r--@ 1 lixia wheel 150K Feb 24 23:14 package-optimize-app1.jar-rw-r--r-- 1 lixia wheel 150K Feb 24 23:14 package-optimize-app2.jar-rw-r--r-- 1 lixia wheel 150K Feb 24 23:14 package-optimize-app3.jarjava-jar devops/package-optimize-app1.jar
The final realization effect
The dependent components of all services are merged into one directory, with a total size of two to three hundred MB, and the transmission efficiency of the first deployment is significantly faster.
The size of each micro-service jar is one or two hundred KB. Daily emergency repair Bug updates and individual jar are basically instant messages.
Each micro-service jar defines a list of components that depend on the specified version, so there will be no conflicting loading of different versions of the component.
Unofficial three-party dependent components can also be referenced normally.
At this point, the study on "how to deploy Jar files in SpringBoot" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.