问题场景:
java项目打了jar中已经包含了各个application-xxx.yml文件,jar所在的同目录中也引入了外部的application.yml、application-test.yml。
目的:运行时,希望使用的时外部application.yml、application-test.yml 文件。
验证过的使用了以下命令:
java -Xms1024m -Xmx2048m -jar -Dspring.config.location=./application.yml /home/test/app-0.0.1.jar --logging.config=./logback.xml -server my-test-app &
或者:
java -Xms1024m -Xmx2048m -jar -Dspring.config.location=./application.yml /home/test/app-0.0.1.jar --logging.config=./logback.xml -server my-test-app &
注意:application.yml 里面需要配置下面属性才能引用到文件application-test.yml
spring:
profiles:
active: test
附上命令含义图:
附上启动jar脚本:
#!/bin/sh
# ./ry.sh start 启动 stop 停止 restart 重启 status 状态
AppName=settlement-admin.jar# JVM参数
JVM OPTS="-Dname=$AppName -Duser.timezone-Asia/Shanghai -Xms512m -Xmx1024m -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDatestamps -XX:+PrintGCDetails -XX:NewRatio=1 -XX:SurvivorRatio=30 -XX:+UseParallelGC -XX:+seParalleloldcc"APP_HOME=`pwd`
LOG_PATH=$APP_HOME/logs/$AppName.log
EVN=testif ["$1”=""];
then
echo -e "\033[0;31m 未输入操作名 \033[0m \033[0;34m {startIstoplrestartlstatus] \033[0m”exit 1
fi
if["$AppName" =""];then
echo -e“033[0;31m 未输入应用名 \033[0m"exit 1
fi
function start(){
PID= `ps -ef |grep javalgrep $AppName|grep -v grep|awk '(print $2)'`
if [ x"$PID"!= x"" ]; thenecho "SAppName is running..."
else
nohup java $JVM_OPTS -jar -Dspring.config.location=./application.yml $AppName > /dev/null 2>&1 &echo "start SAppName success..."
fi}
function stop()
{
echo"stop $AppName"
PID=""
query(){
PID=`ps -ef |grep java|grep $AppNamelgrep -v grep|awk '{print $2}'`
}query
if [ x"SPID” != x" ]; then
k111 -TERM $PID
echo "$AppName(pid:$PID) exiting..."
while[ x"$PID”!= x""]
do
sleep1
done
echo "$AppName exited."
else
echo "$AppName already stopped."fi
}function restart()
{
stop
sleep 2
start
}
function status()
{
PID = `ps -ef | grep java | grep $AppName|grep -v grep|wc -l`
if [$PID !=0];then
echo "$AppName is running..."
else
echo "$AppName is not running..."
fi
}
case $1 in
start)
start;;
stop)
stop;;
restart)
restart;;
status)
status;;
*)
esac