Spring Shell打Jar包時(shí)常用小技巧
1、Main-Class
spring-shell項(xiàng)目打Jar包的一個(gè)必要條件就是,指定Main-Class為org.springframework.shell.Bootstrap
一般情況下,如果想在IDE中直接運(yùn)行項(xiàng)目,顯示在控制臺(tái)中,也會(huì)調(diào)用org.springframework.shell.Bootstrap中的Main方法。如下:
import org.springframework.shell.Bootstrap;import java.io.IOException;public class HelloApplication { public static void main(String[] args) throws IOException { Bootstrap.main(args); }}
2、配置讀取新xml文件
spring-shell項(xiàng)目,要求在resource/META-INF/spring目錄下,必須有一個(gè)spring-shell-plugin.xml文件,打Jar包的時(shí)候必須要包括這個(gè)文件。
在IDEA中,Maven項(xiàng)目是會(huì)默認(rèn)掃描resource目錄的,但是打成Jar包的時(shí)候, 是不會(huì)掃描的。我也不知道為什么,只是只是此時(shí)最好在pom.xml中配置一下,讓它讀取這個(gè)xml文件:
<resources> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.xml</include> </includes> </resource> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource></resources>
PS:src/main/java目錄下的xml文件也得讀。如果把上面這兩個(gè)<resource>合并到一起,寫成<directory>src/main</directory>,反而是不對(duì)的。太奇怪了。
3、打包多個(gè)Jar包
如果項(xiàng)目打Jar包時(shí),需要依賴于另外一個(gè)spring-shell的Jar包,可以直接在pom.xml中添加依賴,這樣就會(huì)把所有的新增的命令合并到一起
<dependencies> <dependency> <groupId>cn.com.bignzi</groupId> <artifactId>dcore</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <dependency> <groupId>cn.com.bignzi</groupId> <artifactId>plugin.data</artifactId> <version>0.0.1-SNAPSHOT</version></dependencies>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. js select支持手動(dòng)輸入功能實(shí)現(xiàn)代碼2. 如何在PHP中讀寫文件3. java加載屬性配置properties文件的方法4. PHP正則表達(dá)式函數(shù)preg_replace用法實(shí)例分析5. 什么是Python變量作用域6. 《Java程序員修煉之道》作者Ben Evans:保守的設(shè)計(jì)思想是Java的最大優(yōu)勢(shì)7. CSS3中Transition屬性詳解以及示例分享8. php redis setnx分布式鎖簡(jiǎn)單原理解析9. bootstrap select2 動(dòng)態(tài)從后臺(tái)Ajax動(dòng)態(tài)獲取數(shù)據(jù)的代碼10. vue使用moment如何將時(shí)間戳轉(zhuǎn)為標(biāo)準(zhǔn)日期時(shí)間格式
