spring boot項(xiàng)目沒有mainClass如何實(shí)現(xiàn)打包運(yùn)行
springboot項(xiàng)目沒有mainClass實(shí)現(xiàn)打包運(yùn)行
項(xiàng)目分為兩個(gè)部分,一個(gè)是業(yè)務(wù)代碼模塊,一個(gè)是框架模塊,運(yùn)行class放在框架部分,那業(yè)務(wù)代碼如何配置才能正常運(yùn)行?
框架starter運(yùn)行類如下
@SpringBootApplication( ? ? scanBasePackages = {"com"} ) public class Starter {
@SpringBootApplication只會掃描@SpringBootApplication注解標(biāo)記類包下及其子包的類(特定注解標(biāo)記,比如說@Controller,@Service,@Component,@Configuration和@Bean注解等等)納入到spring容器,如果不在@SpringBootApplication注解標(biāo)記類相同包下及其子包的類,需要我們?nèi)ヅ渲靡幌聮甙窂?,即scanBasePackages 。
業(yè)務(wù)代碼模塊如何配置?
借助spring-boot-maven-plugin配置如下
<plugin> ? ? ? ? ? ? ? ? <groupId>org.springframework.boot</groupId> ? ? ? ? ? ? ? ? <artifactId>spring-boot-maven-plugin</artifactId> ? ? ? ? ? ? ? ? <configuration> ? ? ? ? ? ? ? ? ? ? <mainClass>com.core.Starter</mainClass> ? ? ? ? ? ? ? ? ? ? <layout>ZIP</layout> ? ? ? ? ? ? ? ? ? ? <classifier>exec</classifier> ? ? ? ? ? ? ? ? ? ? <includeSystemScope>true</includeSystemScope> ? ? ? ? ? ? ? ? </configuration> ? ? ? ? ? ? ? ? <executions> ? ? ? ? ? ? ? ? ? ? <execution> ? ? ? ? ? ? ? ? ? ? ? ? <goals> ? ? ? ? ? ? ? ? ? ? ? ? ? ? <goal>repackage</goal> ? ? ? ? ? ? ? ? ? ? ? ? </goals> ? ? ? ? ? ? ? ? ? ? </execution> ? ? ? ? ? ? ? ? </executions> ? ? ? ? ? ? </plugin>
mainClass最終會在jar包里的MANIFEST.MF文件中指定
Start-Class: com.core.Starter
Spring Boot Maven plugin的5個(gè)Goals
spring-boot:repackage
,默認(rèn)goal。在mvn package之后,再次打包可執(zhí)行的jar/war,同時(shí)保留mvn package生成的jar/war為.originspring-boot:run
,運(yùn)行Spring Boot應(yīng)用spring-boot:start
,在mvn integration-test階段,進(jìn)行Spring Boot應(yīng)用生命周期的管理spring-boot:stop
,在mvn integration-test階段,進(jìn)行Spring Boot應(yīng)用生命周期的管理spring-boot:build-info
,生成Actuator使用的構(gòu)建信息文件build-info.properties
layout屬性的值可以如下:
JAR
,即通常的可執(zhí)行jarMain-Class
: org.springframework.boot.loader.JarLauncherWAR
,即通常的可執(zhí)行war,需要的servlet容器依賴位于WEB-INF/lib-providedMain-Class
: org.springframework.boot.loader.warLauncherZIP
,即DIR,類似于JARMain-Class
: org.springframework.boot.loader.PropertiesLauncherMODULE
,將所有的依賴庫打包(scope為provided的除外),但是不打包Spring Boot的任何LauncherNONE
,將所有的依賴庫打包,但是不打包Spring Boot的任何Launcher
classifier
生成可執(zhí)行jar包的后綴名
includeSystemScope
將system范圍依賴包也打進(jìn)來,如
<dependency> ? ? ? ? ? ? <groupId>com.alipay</groupId> ? ? ? ? ? ? <artifactId>alipay-sdk-java</artifactId> ? ? ? ? ? ? <version>1.1</version> ? ? ? ? ? ? <scope>system</scope> ? ? ? ? ? ? <systemPath> ? ? ? ? ? ? ? ? ${project.basedir}/local_repo/com/alipay/alipay-sdk-java/1.1/alipay-sdk-java-1.1.jar ? ? ? ? ? ? </systemPath> ? ? ? ? </dependency>
使用maven打包指定mainClass
<build> ? ? ? ? <plugins> ? ? ? ? ? ? <plugin> ? ? ? ? ? ? ? ? <groupId>org.springframework.boot</groupId> ? ? ? ? ? ? ? ? <artifactId>spring-boot-maven-plugin</artifactId> ? ? ? ? ? ? ? ? <configuration> ? ? ? ? ? ? ? ? ? ? <mainClass>com.xxx.XxxApplication</mainClass> ? ? ? ? ? ? ? ? </configuration> ? ? ? ? ? ? ? ? <executions> ? ? ? ? ? ? ? ? ? ? <execution> ? ? ? ? ? ? ? ? ? ? ? ? <goals> ? ? ? ? ? ? ? ? ? ? ? ? ? ? <goal>repackage</goal> ? ? ? ? ? ? ? ? ? ? ? ? </goals> ? ? ? ? ? ? ? ? ? ? </execution> ? ? ? ? ? ? ? ? </executions> ? ? ? ? ? ? </plugin> ? ? ? ? </plugins> ? ? </build>
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Java基于Swing和netty實(shí)現(xiàn)仿QQ界面聊天小項(xiàng)目
這篇文章主要為大家詳細(xì)介紹了Java如何利用Swing和netty實(shí)現(xiàn)仿QQ界面聊天小項(xiàng)目,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下2022-09-09Java使用線程實(shí)現(xiàn)異步運(yùn)行的方法
在Java中,實(shí)現(xiàn)異步運(yùn)行的一個(gè)常用方式是使用Thread類,這篇文章主要介紹了Java使用線程實(shí)現(xiàn)異步運(yùn)行,需要的朋友可以參考下2024-07-07Java編程用兩個(gè)棧實(shí)現(xiàn)隊(duì)列代碼分享
這篇文章主要介紹了Java編程用兩個(gè)棧實(shí)現(xiàn)隊(duì)列代碼分享,具有一定參考價(jià)值,這里給大家分享下,供需要的朋友了解。2017-10-10JavaWeb實(shí)現(xiàn)用戶登錄注冊功能實(shí)例代碼(基于Servlet+JSP+JavaBean模式)
這篇文章主要基于Servlet+JSP+JavaBean開發(fā)模式實(shí)現(xiàn)JavaWeb用戶登錄注冊功能實(shí)例代碼,非常實(shí)用,本文介紹的非常詳細(xì),具有參考借鑒價(jià)值,感興趣的朋友一起看看吧2016-05-05Java GUI圖形界面開發(fā)實(shí)現(xiàn)小型計(jì)算器流程詳解
本文章向大家介紹Java GUI圖形界面開發(fā)實(shí)現(xiàn)小型計(jì)算器,主要包括布局管理器使用實(shí)例、應(yīng)用技巧、基本知識點(diǎn)總結(jié)和需要注意事項(xiàng),具有一定的參考價(jià)值,需要的朋友可以參考一下2022-08-08Spring Boot 深入分析AutoConfigurationImportFilter自動化條件
這篇文章主要分析了Spring Boot AutoConfigurationImportFilter自動化條件配置源碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2022-07-07