Files
AuthCenterConsoleApp/bash/build_class.sh

78 lines
2.3 KiB
Bash
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
# AuthCenter 编译+启动一体化脚本Termux专属
# 特性任意目录可执行、自动定位项目根、清空旧class、全日志输出
# 放置位置AuthCenterConsoleApp/bash/ 下(任意位置也能跑)
# 核心:自动定位项目根目录(无论脚本放哪/在哪执行都能精准找到src上级
find_project_root() {
local current_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# 向上查找直到找到src目录即为项目根
while [ ! -d "${current_dir}/src" ] && [ "${current_dir}" != "/" ]; do
current_dir=$(dirname "${current_dir}")
done
if [ "${current_dir}" = "/" ]; then
echo "❌ 未找到项目根目录无src文件夹"
exit 1
fi
echo "${current_dir}"
}
# 锚定项目根+防呆
BASE_DIR=$(find_project_root)
SRC_DIR="${BASE_DIR}/src"
LIB_DIR="${BASE_DIR}/libs"
OUT_DIR="${BASE_DIR}/runtime"
LOG_DIR="${BASE_DIR}/logs"
MAIN_CLASS="Main" # 主类名
# 前置校验
if [ ! -d "${SRC_DIR}" ]; then
echo "❌ 项目根目录[${BASE_DIR}]下无src目录请核对结构"
exit 1
fi
# 查找Java源文件
JAVA_FILES=$(find "${SRC_DIR}" -name "*.java")
if [ -z "${JAVA_FILES}" ]; then
echo "❌ src目录下无.java源文件"
exit 1
fi
# 1. 清空旧文件+建目录
echo "🧹 清理旧编译文件..."
rm -rf "${OUT_DIR}"/*
mkdir -p "${OUT_DIR}" "${LOG_DIR}"
# 2. 拼接classpathTermux兼容含依赖+输出目录)
CP_PARAM=""
if [ -d "${LIB_DIR}" ]; then
JAR_LIST=("${LIB_DIR}"/*.jar)
if [ -f "${JAR_LIST[0]}" ]; then
CP="${OUT_DIR}:$(IFS=:; echo "${JAR_LIST[*]}")"
CP_PARAM="-cp ${CP}"
else
echo " libs目录无jar包无依赖编译"
CP_PARAM="-cp ${OUT_DIR}"
fi
else
echo " 无libs目录无依赖编译"
CP_PARAM="-cp ${OUT_DIR}"
fi
# 3. 打印目录信息
echo "📌 项目目录信息"
echo " 根目录 ${BASE_DIR}"
echo " 源码数 $(echo "${JAVA_FILES}" | wc -l | tr -d ' ')"
echo " 输出目录:${OUT_DIR}"
echo "------------------------------------------------------------------------"
# 4. 编译源码
echo "开始编译Termux+Java7兼容..."
javac -encoding UTF-8 -source 1.7 -target 1.7 ${CP_PARAM} -d "${OUT_DIR}" ${JAVA_FILES}
if [ $? -ne 0 ]; then
echo -e "\n❌ 编译失败排查JDK版本、源码语法、libs依赖包"
exit 1
fi
echo -e "\n✅ 编译成功!"