Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How can spring boot project be packaged and run without mainClass

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

What this article shares with you is about how the spring boot project can be packaged and run without mainClass. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it.

The springboot project does not have a mainClass implementation to package and run

The project is divided into two parts, one is the business code module, the other is the framework module, running class is placed in the framework part, then how to configure the business code to run normally?

The framework starter running class is @ SpringBootApplication (scanBasePackages = {"com"}) public class Starter {

@ SpringBootApplication only scans the classes under the @ SpringBootApplication annotation class package and its subpackages (specific annotation tags, such as @ Controller,@Service,@Component,@Configuration and @ Bean annotations, etc.) into the spring container. If you are not under the same package of the @ SpringBootApplication annotation tag class and its subpackages, you need to configure the package sweep path, that is, scanBasePackages.

How to configure the business code module?

With spring-boot-maven-plugin, the configuration is as follows

Org.springframework.boot spring-boot-maven-plugin com.core.Starter ZIP exec true repackage

MainClass will eventually be specified in the MANIFEST.MF file in the jar package

Start-Class: com.core.Starter

5 Goals of Spring Boot Maven plugin

Spring-boot:repackage, default goal. After mvn package, package the executable jar/war again, while leaving the jar/war generated by mvn package as .origin

Spring-boot:run, running the Spring Boot application

Spring-boot:start, in the mvn integration-test phase, manages the life cycle of Spring Boot applications.

Spring-boot:stop, in the mvn integration-test phase, manages the life cycle of Spring Boot applications.

Spring-boot:build-info to generate the build information file build-info.properties used by Actuator

The value of the layout attribute can be as follows:

JAR, the usual executable jar

Main-Class: org.springframework.boot.loader.JarLauncher

WAR, the usual executable war, requires servlet containers that depend on the WEB-INF/lib-provided

Main-Class: org.springframework.boot.loader.warLauncher

ZIP, or DIR, is similar to JAR

Main-Class: org.springframework.boot.loader.PropertiesLauncher

MODULE, packaging all dependent libraries (except those whose scope is provided), but not any Launcher of Spring Boot

NONE, packaging all dependent libraries, but not any Launcher of Spring Boot

Classifier

Generate the suffix name of the executable jar package

IncludeSystemScope

Type the system scope dependency package as well, such as

Com.alipay alipay-sdk-java 1.1 system ${project.basedir} / local_repo/com/alipay/alipay-sdk-java/1.1/alipay-sdk-java-1.1.jar use maven packaging to specify mainClass org.springframework.boot Spring-boot-maven-plugin com.xxx.XxxApplication repackage What is springboot? springboot, a new programming specification. It is designed to simplify the initial construction and development process of new Spring applications. SpringBoot is also a framework that serves the framework, and the scope of services is to simplify configuration files.

The above is how the spring boot project can be packaged and run without mainClass. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report