使用springBoot項(xiàng)目配置文件位置調(diào)整到打包外
項(xiàng)目目錄

問題痛點(diǎn):
當(dāng)我們打包一個(gè)項(xiàng)目的時(shí)候,springboot打包的jar都是把resouce下的配置文件打進(jìn)去了,這樣就沒發(fā)修改配置文件
解決方案
- 1.打包的時(shí)候指定打包路徑
- 2.將配置文件從resouce下面移出來
這兩種方案其實(shí)都涉及到一個(gè)maven打包配置問題
首先來談?wù)剬⑴渲梦募膔esouce下面移出來怎么解決
1在項(xiàng)目src同級(jí)別目錄建
config目錄
2.將resouce下的
application.yaml 文件移到config目錄下方便打包后可以配置application文件中相關(guān)配置
pom.xml中的打包配置
<build>
<resources>
<resource>
<directory>config</directory>
<includes>
<include>*.yaml</include>
<include>*.xml</include>
<include>*.conf</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<!--過濾掉的 -->
<!-- <excludes>-->
<!-- <exclude>**/*.properties</exclude>-->
<!-- <exclude>**/*.xml</exclude>-->
<!-- <exclude>**/*.yml</exclude>-->
<!-- </excludes>-->
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions></executions>
<configuration>
<!-- 生成可執(zhí)行的jar的名字:xxx-exec.jar -->
<!-- 不固定,寫成abcd都可以 -->
<classifier>exec</classifier>
<mainClass>com.cloudwise.douc.zabbix.api.DoucZabbixApplication</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
assembly.xml配置
<assembly
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>bin</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<outputDirectory>./</outputDirectory>
<includes>
<include>README*</include>
<include>LICENSE*</include>
<include>NOTICE*</include>
</includes>
</fileSet>
<fileSet>
<directory>config</directory>
<outputDirectory>config</outputDirectory>
</fileSet>
<fileSet>
<directory>bin</directory>
<outputDirectory>bin</outputDirectory>
<fileMode>777</fileMode>
</fileSet>
<fileSet>
<directory>target</directory>
<outputDirectory>lib</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<!--是否把本項(xiàng)目添加到依賴文件夾下-->
<useProjectArtifact>true</useProjectArtifact>
<outputDirectory>lib</outputDirectory>
<!--將scope為runtime的依賴包打包-->
<!--<scope>runtime</scope>-->
</dependencySet>
</dependencySets>
</assembly>
sh啟動(dòng)類shell腳本
#!/bin/bash
PWDPATH=`dirname $0`
COMM_HOME=`cd $PWDPATH && cd .. && pwd`
cd $COMM_HOME
start () {
JVM_OPTS="
-server
-Xms1g
-Xmx1g
-XX:+AlwaysPreTouch
-XX:+UseG1GC
-XX:MaxGCPauseMillis=2000
-XX:GCTimeRatio=4
-XX:InitiatingHeapOccupancyPercent=30
-XX:G1HeapRegionSize=8M
-XX:ConcGCThreads=2
-XX:G1HeapWastePercent=10
-XX:+UseTLAB
-XX:+ScavengeBeforeFullGC
-XX:+DisableExplicitGC
-XX:+PrintGCDetails
-XX:-UseGCOverheadLimit
-XX:+PrintGCDateStamps
-Xloggc:logs/gc.log
-Dlog4j2.configurationFile=config/log4j2.xml
"
export CLASSPATH=$JAVA_HOME/jre/lib/*:$JAVA_HOME/lib/*:$COMM_HOME/lib/*
# 啟動(dòng)類路徑
export MAINCLASS="com.gug.api.AdimApplication"
case $1 in
-b )
nohup java $JVM_OPTS -cp $CLASSPATH $MAINCLASS 1>/dev/null 2>&1 &
;;
-d )
java $JVM_OPTS -classpath $CLASSPATH $MAINCLASS
;;
esac
echo -e '\r'
}
case $1 in
restart )
echo stop
PID=`ps avx|grep $COMM_HOME|grep -v 'grep'|awk '{print $1}'`
if [ ! -n "$PID" ] ;then
echo "The current process does not exist."
else
kill $PID
echo "The process has been successfully stopped."
fi
echo start
if [ ! -n "$2" ] ;then
echo "After start, you must add parameters -d or -b. See help for details."
else
start $2 -b
fi
;;
start )
echo start
if [ ! -n "$2" ] ;then
echo "After start, you must add parameters -d or -b. See help for details."
else
start $2
fi
;;
stop )
echo stop
PID=`ps avx|grep $COMM_HOME|grep -v 'grep'|awk '{print $1}'`
if [ ! -n "$PID" ] ;then
echo "The current process does not exist."
else
kill $PID
echo "The process has been successfully stopped."
fi
;;
pid )
PID=`ps avx|grep $COMM_HOME|grep -v 'grep'|awk '{print $1}'`
if [ ! -n "$PID" ] ;then
echo "The current process does not exist."
else
echo "pid : "${PID}
fi
;;
status )
PID=`ps avx|grep $COMM_HOME|grep -v 'grep'|awk '{print $1}'`
if [ ! -n "$PID" ] ;then
echo "dead"
else
echo "running"
fi
;;
help )
echo 'start -d or -b Start the service DEBUG mode or background mode.'
echo 'stop Stop the service running in the background.'
echo 'pid Gets the current process id information.'
echo 'status Gets the current service status information.'
;;
* )
echo Command error, please enter help
;;
esac
總結(jié):
當(dāng)打包過程中出現(xiàn)各種問題后,及時(shí)的去查找問題,一般注意pom中的配置打包是否沒有把某些包打進(jìn)去還有就是啟動(dòng)sell腳本通過 ./Aplication.sh start -d 顯示啟動(dòng)日志
到此這篇使用springBoot項(xiàng)目配置文件位置調(diào)整到打包外文章就介紹到這了,更多相關(guān)springBoot項(xiàng)目配置文件位置調(diào)整到打包外的內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Mybatis結(jié)果集自動(dòng)映射的實(shí)例代碼
在使用Mybatis時(shí),有的時(shí)候我們可以不用定義resultMap,而是直接在<select>語(yǔ)句上指定resultType。這個(gè)時(shí)候其實(shí)就用到了Mybatis的結(jié)果集自動(dòng)映射,下面通過本文給大家分享Mybatis結(jié)果集自動(dòng)映射的實(shí)例代碼,一起看看吧2017-02-02
JavaFX如何獲取ListView(列表視圖)的選項(xiàng)
這篇文章主要介紹了JavaFX如何獲取ListView(列表視圖)的選項(xiàng),具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-01-01
Java 集合實(shí)現(xiàn)分頁(yè)的方法(業(yè)務(wù)代碼實(shí)現(xiàn)分頁(yè))
在Java開發(fā)中,有些場(chǎng)景比較復(fù)雜,受限制,不好在sql查詢層面實(shí)現(xiàn)分頁(yè),需要在查詢的list結(jié)果后,將list分頁(yè)返回,如何實(shí)現(xiàn)呢,帶著這個(gè)問題一起通過本文學(xué)習(xí)吧2025-02-02
Eclipse不自動(dòng)編譯java文件的終極解決方法
這篇文章主要介紹了Eclipse不自動(dòng)編譯java文件的終極解決方法,需要的朋友可以參考下2015-12-12
springboot整合quartz實(shí)現(xiàn)定時(shí)任務(wù)示例
spring支持多種定時(shí)任務(wù)的實(shí)現(xiàn)。我們來介紹下使用spring的定時(shí)器和使用quartz定時(shí)器,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-04-04
小議Java的源文件的聲明規(guī)則以及編程風(fēng)格
這篇文章主要介紹了小議Java的源文件的聲明規(guī)則以及編程風(fēng)格,僅給Java初學(xué)者作一個(gè)簡(jiǎn)單的示范,需要的朋友可以參考下2015-09-09

