In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "Spring Boot play an executable Jar package method", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "Spring Boot play an executable Jar package method" bar!
Traditional Java applications need to pack a war package and run it in the Tomcat webapps directory.
Java supports Jar packages, but does not provide a standard way to load and embed other Jar packages in a Jar package, which generally requires an extended class loader. Even so, it cannot be run as a package, because there is no Servlet container.
With the Spring Boot framework, all this becomes simple, and we can easily break the application into an executable Jar package.
How to run it as a Jar package? 1. Add plug-in org.springframework.boot spring-boot-maven-plugin repackage exec-$ {env}
Here is to add a Maven packaging plug-in, through the configuration can be customized into the format of the Jar package, such as: javastack-exec-dev.jar.
If you are using Spring Boot in the spring-boot-starter-parent way, you do not need to write the executions option because it includes the executions repackage build configuration.
For more use of this plug-in, refer to:
Https://docs.spring.io/spring-boot/docs/2.1.3.RELEASE/maven-plugin/usage.html
2. Pack it into a Jar package
It can be packaged using the mvn package command or the Maven plug-in in IDE. If you are not familiar with Maven, please follow the official account of Java technology stack Wechat, and reply in the background: maven, I have sorted out the chief of the dry goods stack.
After packing, you can see the Jar package in the project target directory.
In addition to the compiled class file, this Jar package also has a built-in Servlet container and integrates all other Jar package libraries you need to rely on. Let's take a look at the directory structure of the Jar package.
├─ BOOT-INF │ ├─ classes │ │ └─ cn │ │ └─ javastack │ │ └─ demo │ └─ lib ├─ META-INF │ └─ maven │ └─ cn.javastack demo org springframework boot loader archive data ├─ jar └─ util
Find the application startup class in the file\ META-INF\ MANIFEST.MF:
Manifest-Version: 1.0Archiver-Version: Plexus ArchiverBuilt-By: javastackStart-Class: cn.javastack.demo.ApplicationSpring-Boot-Classes: BOOT-INF/classes/Spring-Boot-Lib: BOOT-INF/lib/Spring-Boot-Version: 2.1.3.RELEASECreated-By: Apache Maven 3.5.0Build-Jdk: 1.8.0_151Main-Class: org.springframework.boot.loader.JarLauncher3, run the Jar package
Run the command format:
$java-jar xxx.jar
For more use of this command, please see this article: Java Jar package compression and decompression instructions, or follow the Java technology stack Wechat official account, reply in the background: java.
Run the command to demonstrate:
$java-jar javastack-exec-dev.jar
. _ _ / / _ _ _ (() _ _ _ |'_ _ _ | |\ / _ _ _ | | | (_ _ | |) )'| _ |. _ _ | _ | | _ | _ | | _\ _ _ | / = | _ | = | _ _ / = / _ /:: Spring Boot:: (v2.1.3.RELEASE). . . . . . . (log output here). . . . Started Example in 2.536 seconds (JVM running for 2.864)
All right, here we go.
Thank you for your reading, the above is the content of "Spring Boot playing an executable Jar package". After the study of this article, I believe you have a deeper understanding of the method of Spring Boot playing an executable Jar package, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.