You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/bin/bash
# 快速启动脚本 - 自动下载、编译、启动Web服务器
echo "========================================="
echo " 快速启动Web聊天服务器"
echo "========================================="
echo ""
# 检查Java
if ! command -v java &> /dev/null; then
echo "❌ 未找到Java请先安装Java 11+"
exit 1
fi
# 检查web文件
if [ ! -f "web/index.html" ]; then
echo "❌ 错误: 找不到web/index.html文件"
echo "请确保在项目根目录运行此脚本"
exit 1
fi
# 下载Gson
if [ ! -f "lib/gson-2.10.1.jar" ]; then
echo "📦 下载依赖..."
mkdir -p lib
if command -v wget &> /dev/null; then
wget -q -O lib/gson-2.10.1.jar https://repo1.maven.org/maven2/com/google/code/gson/gson/2.10.1/gson-2.10.1.jar
else
curl -s -o lib/gson-2.10.1.jar https://repo1.maven.org/maven2/com/google/code/gson/gson/2.10.1/gson-2.10.1.jar
fi
fi
# 编译
echo "🔨 编译项目..."
mkdir -p bin
javac -cp "lib/gson-2.10.1.jar" -d bin -encoding UTF-8 src/common/*.java src/server/WebSocketServer.java src/server/WebSocketClient.java 2>&1
if [ $? -ne 0 ]; then
echo "❌ 编译失败"
exit 1
fi
# 启动
echo "✅ 编译成功"
echo ""
echo "🚀 启动Web服务器..."
echo "📱 访问地址: http://localhost:8080"
echo "🌐 局域网访问: http://$(hostname -I | awk '{print $1}'):8080"
echo ""
echo "按 Ctrl+C 停止服务器"
echo ""
cd bin
java -cp ".:../lib/gson-2.10.1.jar" server.WebSocketServer