Files
integral-shop/restart-backend.command

60 lines
2.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# 双击此文件即可在新终端启动 backend
# 1) 杀掉占用 20600 的旧进程
# 2) 用 Maven 把 crmeb-common / crmeb-service 安装到本地 m2这样 crmeb-admin 单模块运行时能找到依赖)
# 3) 进入 crmeb-admin 目录,用完整 GAV 调用 spring-boot:run
set -e
cd "$(dirname "$0")"
PROFILE="${BACKEND_PROFILE:-byjyw149}"
echo "🛑 Stopping any process listening on :20600 ..."
PIDS=$(lsof -t -iTCP:20600 -sTCP:LISTEN 2>/dev/null || true)
if [ -n "$PIDS" ]; then
echo " killing PIDs: $PIDS"
kill -9 $PIDS 2>/dev/null || true
sleep 2
else
echo " no existing process on :20600"
fi
# 自动定位 Java沿用 start-backend.sh 的逻辑)
find_java() {
if /usr/libexec/java_home &>/dev/null; then
echo "$(/usr/libexec/java_home)/bin/java"; return
fi
for p in /opt/homebrew/opt/openjdk*/bin/java /opt/homebrew/opt/openjdk/bin/java \
/usr/local/opt/openjdk*/bin/java /usr/local/opt/openjdk/bin/java; do
[ -x "$p" ] && echo "$p" && return
done
[ -n "$SDKMAN_DIR" ] && [ -x "$SDKMAN_DIR/candidates/java/current/bin/java" ] && \
echo "$SDKMAN_DIR/candidates/java/current/bin/java" && return
command -v java 2>/dev/null
}
JAVA_BIN=$(find_java)
if [ -z "$JAVA_BIN" ]; then
echo "❌ 未找到 Java请先安装 JDK 11brew install openjdk@11"
exit 1
fi
export JAVA_HOME="$(dirname "$(dirname "$JAVA_BIN")")"
echo "☕ Java: $JAVA_BIN"
"$JAVA_BIN" -version
echo ""
cd backend
# 第一步:把依赖模块编译并安装到本地 m2首次执行会下载依赖只在源代码变更后需要重跑
echo "🔧 Step 1: install crmeb-common + crmeb-service to local m2 ..."
echo ""
./mvnw install -pl crmeb-common,crmeb-service -am -Dmaven.test.skip=true -q
# 第二步:进入 crmeb-admin 单模块跑 spring-boot:run避免根 pom 触发 main class 错误)
echo ""
echo "🚀 Step 2: launch crmeb-admin (profile=$PROFILE) ..."
echo ""
cd crmeb-admin
exec ../mvnw \
org.springframework.boot:spring-boot-maven-plugin:2.3.0.RELEASE:run \
-Dmaven.test.skip=true \
-Dspring-boot.run.profiles="$PROFILE"