#!/bin/bash
# 获取用户输入的服务名称 SERVICE_NAME=$1
# 检查是否输入参数 if [ -z "$SERVICE_NAME" ]; then echo "Usage: ./run.sh <servicename|all>" exit 1 fi
# 定义运行单个服务的函数 run_service() { local service=$1 echo "Building and running $service..." mvn clean install -pl $service -am mvn spring-boot:run -pl $service }
# 如果输入 "all",运行所有服务 if [ "$SERVICE_NAME" == "all" ]; then echo "Building and running all services..." mvn clean install # 假设所有 Spring Boot 模块都在根目录下 for module in $(mvn help:evaluate -Dexpression=project.modules -q -DforceStdout | sed -e 's/<[^>]*>//g' -e 's/\s*//g' | tr ',' '\n'); do echo "Running $module..." mvn spring-boot:run -pl $module & done else # 运行指定的单个服务 run_service $SERVICE_NAME fi
|