赞
踩
spring boot在打包时候利用maven打包控件以及启动脚本配置,将配置文件打包到jar包的外面,方便配置部署。
1. spring boot maven打包控件
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.7</version>
</plugin>
</plugins>
</build>
2. maven打包控件
在打包时请在maven中选定no_config profile
<profiles>
<profile>
<id>no_config</id>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>*/**</include>
</includes>
<excludes>
<exclude>
config/*.properties
</exclude>
<exclude>
*.properties
</exclude>
<exclude>
*.xml
</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin> <!--jdk版本设置-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<compilerArguments>
<bootclasspath>C:\Program Files\Java\jdk1.8.0_141\jre\lib\rt.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>
</profile>
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
3. 启动jar包与配置文件放置说明
请将打包的spring boot jar包与配置文件放置在同一文件目录,例如文件目录
4. 配置启动脚本
cd /xxx/spring-boot-demo #项目目录
#export LC_CTYPE=zh_CN.GBK
path='/xxx/spring-boot-demo'#项目目录
year=`date +%Y`
month=`date +%m`
day=`date +%d`
echo Running ...
if [ ! -d $path/log/$year/$month/$day ];then
mkdir -p $path/log/$year/$month/$day
fi
nohup /usr/jdk1.8.0_40/bin/java -jar -Xmx2048m -Xms1024m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=6666 -Dspring.profiles.active=local -Dlogging.config=./logback.xml spring-boot-demo.jar >> /dev/null 2>&1 &
echo The end!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。