idea一键主动化摆设项目

[复制链接]
发表于 2026-1-25 02:05:34 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×

媒介

一键主动化摆设项目是当代软件开发中的一种高效实践,它带来了许多显着的利益:


  • 进步服从:主动化摆设可以节流手动摆设所需的时间。特殊是在频仍摆设的环境下,主动化可以显着淘汰重复性工作,让开发职员有更多时间专注于编码息争决题目。
  • 淘汰错误:手动摆设过程轻易堕落,尤其是在复杂的摆设流程中。主动化摆设可以淘汰人为错误,确保每次摆设都是划一和可靠的。
  • 快速回滚:如果新摆设的版本出现题目,主动化摆设流程可以快速回滚到上一个稳固版本,淘汰体系不可用的时间。
  • 一连集成和一连摆设(CI/CD):主动化摆设是CI/CD流程的关键构成部门,它答应开发团队快速迭代和发布新功能,进步软件交付的速率和质量。
  • 尺度化流程:主动化摆设有助于尺度化摆设流程,确保全部团队成员都遵照雷同的步调和尺度,这有助于维护代码和摆设的划一性。

提示:文章一共先容2种方式,下面案例可供参考
一、 IDEA插件安装

1. 起首下载 Alibaba Cloud Toolkit 插件


2. 插件下载完成后重启IDEA


二、SpringBoot项目预备

1. pom.xml 文件

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3.          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4.     <modelVersion>4.0.0</modelVersion>
  5.     <parent>
  6.         <groupId>org.springframework.boot</groupId>
  7.         <artifactId>spring-boot-starter-parent</artifactId>
  8.         <version>2.7.3</version>
  9.         <relativePath/> <!-- lookup parent from repository -->
  10.     </parent>
  11.     <groupId>com.test</groupId>
  12.     <artifactId>demo-test</artifactId>
  13.     <version>1.0.0-SNAPSHOT</version>
  14.     <name>demo-test</name>
  15.     <description>demo-test</description>
  16.     <properties>
  17.         <java.version>8</java.version>
  18.     </properties>
  19.     <dependencies>
  20.         <dependency>
  21.             <groupId>org.springframework.boot</groupId>
  22.             <artifactId>spring-boot-starter-web</artifactId>
  23.         </dependency>
  24.         <dependency>
  25.             <groupId>org.springframework.boot</groupId>
  26.             <artifactId>spring-boot-starter-test</artifactId>
  27.             <scope>test</scope>
  28.         </dependency>
  29.     </dependencies>
  30.     <build>
  31.         <plugins>
  32.             <plugin>
  33.                 <groupId>org.springframework.boot</groupId>
  34.                 <artifactId>spring-boot-maven-plugin</artifactId>
  35.             </plugin>
  36.         </plugins>
  37.     </build>
  38. </project>
复制代码
2. controller

  1. package com.test.controller;
  2. import org.springframework.web.bind.annotation.*;
  3. @RestController
  4. @RequestMapping("demo")
  5. public class TestController {
  6.     /**
  7.      * 测试接口
  8.      *
  9.      * @param version 版本号
  10.      * @return 版本号
  11.      */
  12.     @GetMapping("query")
  13.     public String query(@RequestParam String version) {
  14.         System.out.println("打印版本 = " + version);
  15.         return version;
  16.     }
  17. }
复制代码
3. 启动类

  1. package com.test;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. @SpringBootApplication
  5. public class DemoTestApplication {
  6.     public static void main(String[] args) {
  7.         SpringApplication.run(DemoTestApplication.class, args);
  8.     }
  9. }
复制代码

三、SpringBoot项目jar包摆设

1. Alibaba Cloud Toolkit 插件服务器设置


2. 主机 IP、用户名、暗码 点击测试链接


3. 编辑项目设置


4. 选择 Deploy to Host


5. 指定Target Deploy Host 选择添加主机IP,勾选刚添加的服务器


6. 设置服务器jar包存放目次


7. 选择本地要上传的jar包



  • 注意⚠️ 这里肯定要本地的绝对路径

8. 添加启动下令


9. 设置打包下令

  1. clean package install -Dmaven.test.skip=true
复制代码

到这里差不多就设置完了,简单测试一下
10. 测试




11. 摆设脚本


  • 服务器脚本位置
  1. /opt/app/test/deploy/test.sh
复制代码

  • test.sh
  1. #!/bin/bash
  2. # 定义程序路径和文件名的数组
  3. declare -a APP_SERVER_PATHS=("/opt/app/test/")
  4. declare -a APP_SERVERS=("demo-test-1.0.0-SNAPSHOT.jar")
  5. # 停止并重启每个程序
  6. for ((i = 0; i < ${#APP_SERVER_PATHS[@]}; i++)); do
  7.   APP_SERVER_PATH=${APP_SERVER_PATHS[$i]}
  8.   APP_SERVER=${APP_SERVERS[$i]}
  9.   # 查找正在运行的Java进程的PID
  10.   PID=$(ps aux | grep java | grep "$APP_SERVER" | grep -v grep | awk '{print $2}')
  11.   if [ -z "$PID" ]; then
  12.     echo "demo-test-1.0.0 server application $i is not running."
  13.   else
  14.     # 杀死进程
  15.     echo "Stopping demo-test-1.0.0 server application $i (PID: $PID)..."
  16.     kill $PID
  17.     sleep 5
  18.   fi
  19. done
  20. # 确保进程已停止后再启动程序
  21. for ((i = 0; i < ${#APP_SERVER_PATHS[@]}; i++)); do
  22.   APP_SERVER_PATH=${APP_SERVER_PATHS[$i]}
  23.   APP_SERVER=${APP_SERVERS[$i]}
  24.   # 启动程序
  25.   echo "Starting demo-test-1.0.0 server application $i..."
  26.   nohup java -Xms512m -Xmx1024m -Xmn256m -Xss256k -jar "${APP_SERVER_PATH}${APP_SERVER}" --spring.profiles.active=prod > /dev/null 2>&1 &
  27.   echo "demo-test-1.0.0 server application $i restarted successfully."
  28. done
复制代码

  • 修改IDEA 摆设脚本

回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表