Springboot项目 Jenkins/Maven 分离Jar部署

项目配置

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
    <!--这里对应项目的主入口-->
    <mainClass>xxx.xxx.RestApplication</mainClass>
    <includes>
        <include>
            <groupId>nothing</groupId>
            <artifactId>nothing</artifactId>
        </include>
    </includes>
</configuration>
<executions>
    <execution>
        <goals>
            <goal>repackage</goal>
        </goals>
    </execution>
</executions>
</plugin>
<!--将依赖包复制到lib下-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
    <execution>
        <id>copy-dependencies</id>
        <phase>package</phase>
        <goals>
            <goal>copy-dependencies</goal>
        </goals>
        <configuration>
            <!-- 依赖包输出目录,将来不打进jar包里 -->
            <outputDirectory>${project.build.directory}/lib</outputDirectory>
            <overWriteReleases>false</overWriteReleases>
            <overWriteSnapshots>false</overWriteSnapshots>
            <overWriteIfNewer>true</overWriteIfNewer>
            <excludeScope>provided</excludeScope>
        </configuration>
    </execution>
</executions>
</plugin>

启动脚本, 全部使用绝对路径

stop.sh
PID=$(ps -ef|grep jar文件名|grep -v grep|awk '{print $2}')
if [ -z $PID ]; then
    echo "process not exist"
    exit
else
    echo "process id: $PID"
    kill -9 ${PID}
    echo "process killed"
fi
start.sh
/xxxx/xxxxx/stop.sh
nohup java -jar -Xms512M -Xmx2048M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./dump -XX:+UseConcMarkSweepGC -Djava.ext.dirs=/xxxx/xxxxx/lib -Dspring.profiles.active=dev /xxxx/xxxxx/xxxxx-1.0.0.jar > /xxxx/xxxxx/out.log 2>&1 &

Jenkins配置

1632721432(1).png
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容