Termiux运行脚本测试完成
This commit is contained in:
11
.classpath
11
.classpath
@@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-17"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
<?xml version="1.0" encoding="UTF-8"?><classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-17"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
<classpathentry kind="lib" path="libs/nanohttpd-2.3.1.jar"/>
|
||||
</classpath>
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#!/bin/bash
|
||||
# 编译目录配置(已修正源文件目录为实际的src)
|
||||
BASE_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
|
||||
SRC_DIR="$BASE_DIR/src" # 核心修改:源目录从runtime改为src
|
||||
OUT_DIR="$BASE_DIR/src" # class文件输出到src,与源文件同包结构
|
||||
SRC_DIR="$BASE_DIR/src" # java源文件目录
|
||||
OUT_DIR="$BASE_DIR/runtime" # class输出目录(已改回runtime)
|
||||
LIB_DIR="$BASE_DIR/libs" # 依赖包目录
|
||||
|
||||
# 1. 递归查找所有.java源文件
|
||||
JAVA_FILES=$(find "$SRC_DIR" -name "*.java")
|
||||
@@ -11,17 +12,29 @@ if [ -z "$JAVA_FILES" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 2. 确保输出目录存在
|
||||
# 2. 处理依赖包,拼接classpath参数
|
||||
CP_PARAM=""
|
||||
if [ -d "$LIB_DIR" ]; then
|
||||
# 匹配libs下所有jar包,适配Linux/macOS,多个jar用冒号分隔
|
||||
JAR_FILES=$(ls "$LIB_DIR"/*.jar 2>/dev/null)
|
||||
if [ -n "$JAR_FILES" ]; then
|
||||
CP_PARAM="-cp $(echo $JAR_FILES | tr ' ' ':')"
|
||||
fi
|
||||
else
|
||||
echo "警告:依赖目录 $LIB_DIR 不存在,将不加载外部依赖"
|
||||
fi
|
||||
|
||||
# 3. 确保输出目录存在
|
||||
mkdir -p "$OUT_DIR"
|
||||
|
||||
# 3. 执行编译
|
||||
echo "开始编译Java文件,输出目录:$OUT_DIR"
|
||||
javac -d "$OUT_DIR" $JAVA_FILES
|
||||
# 4. 执行编译(带依赖路径)
|
||||
echo "开始编译Java文件,源目录:$SRC_DIR,输出目录:$OUT_DIR"
|
||||
javac $CP_PARAM -d "$OUT_DIR" $JAVA_FILES
|
||||
|
||||
# 4. 结果校验
|
||||
# 5. 结果校验
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "编译成功!class文件已按包结构生成至 $OUT_DIR"
|
||||
else
|
||||
echo "编译失败,请检查Java源文件语法或依赖"
|
||||
echo "编译失败,请检查Java源文件语法或依赖包是否完整"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
14
bash/start_winboll_in_termux.sh
Normal file
14
bash/start_winboll_in_termux.sh
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
# 1. 先跳转到脚本所在目录,再定位项目根目录(核心修复)
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")"
|
||||
BASE_DIR=$(cd .. && pwd) # 从bash目录向上跳1级,得到项目根目录
|
||||
|
||||
# 2. 执行编译(用绝对路径调用build_class.sh,避免路径问题)
|
||||
bash "$BASE_DIR/bash/build_class.sh"
|
||||
|
||||
# 3. 配置类路径(指向根目录的runtime和libs)
|
||||
CLASSPATH="$BASE_DIR/runtime:$BASE_DIR/libs/*"
|
||||
MAIN_CLASS="Main"
|
||||
|
||||
echo "正在启动 Main 类,类路径:$CLASSPATH"
|
||||
java -cp "$CLASSPATH" $MAIN_CLASS
|
||||
BIN
libs/nanohttpd-2.3.1.jar
Normal file
BIN
libs/nanohttpd-2.3.1.jar
Normal file
Binary file not shown.
BIN
runtime/Main.class
Normal file
BIN
runtime/Main.class
Normal file
Binary file not shown.
BIN
runtime/cc/winboll/AuthCenterConsoleApp.class
Normal file
BIN
runtime/cc/winboll/AuthCenterConsoleApp.class
Normal file
Binary file not shown.
BIN
runtime/cc/winboll/LogUtils$CustomLogFormatter.class
Normal file
BIN
runtime/cc/winboll/LogUtils$CustomLogFormatter.class
Normal file
Binary file not shown.
BIN
runtime/cc/winboll/LogUtils.class
Normal file
BIN
runtime/cc/winboll/LogUtils.class
Normal file
Binary file not shown.
BIN
runtime/cc/winboll/auth/AuthCenterHttpService.class
Normal file
BIN
runtime/cc/winboll/auth/AuthCenterHttpService.class
Normal file
Binary file not shown.
BIN
runtime/cc/winboll/config/AuthConfig.class
Normal file
BIN
runtime/cc/winboll/config/AuthConfig.class
Normal file
Binary file not shown.
BIN
runtime/cc/winboll/models/PingPongModel.class
Normal file
BIN
runtime/cc/winboll/models/PingPongModel.class
Normal file
Binary file not shown.
BIN
runtime/cc/winboll/service/AuthService.class
Normal file
BIN
runtime/cc/winboll/service/AuthService.class
Normal file
Binary file not shown.
BIN
runtime/cc/winboll/util/AuthUtils.class
Normal file
BIN
runtime/cc/winboll/util/AuthUtils.class
Normal file
Binary file not shown.
BIN
src/Main.class
Normal file
BIN
src/Main.class
Normal file
Binary file not shown.
@@ -1,4 +1,8 @@
|
||||
import cc.winboll.AuthCenterConsoleApp;
|
||||
import cc.winboll.auth.AuthCenterHttpService;
|
||||
import cc.winboll.LogUtils;
|
||||
import java.io.IOException;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
|
||||
@@ -7,6 +11,11 @@ public class Main {
|
||||
printDetailedRuntimeEnv();
|
||||
System.out.println("Hello World!");
|
||||
//AuthCenterConsoleApp.main(null);
|
||||
|
||||
// 新增:启动 AuthCenterHttpService 服务
|
||||
startAuthCenterHttpService();
|
||||
// 阻塞控制台,防止服务启动后退出,支持手动停止
|
||||
consoleBlockForService();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,6 +62,37 @@ public class Main {
|
||||
System.out.println("========================================\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增:初始化并启动 AuthCenterHttpService
|
||||
*/
|
||||
private static void startAuthCenterHttpService() {
|
||||
int httpPort = 8080; // 服务端口,可自行修改
|
||||
AuthCenterHttpService httpService = new AuthCenterHttpService(httpPort);
|
||||
try {
|
||||
httpService.start();
|
||||
System.out.println("\nAuthCenterHttpService 启动成功,监听端口:" + httpPort);
|
||||
System.out.println("可访问接口:GET http://localhost:" + httpPort + "/authcenter/ping");
|
||||
} catch (IOException e) {
|
||||
System.err.println("AuthCenterHttpService 启动失败!端口 " + httpPort + " 可能被占用");
|
||||
LogUtils.e("Main", "HTTP服务启动异常", e);
|
||||
System.exit(1); // 启动失败退出程序
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增:控制台阻塞,保持服务运行,支持回车停止
|
||||
*/
|
||||
private static void consoleBlockForService() {
|
||||
System.out.println("\n提示:输入任意字符并回车,可停止服务退出程序");
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
scanner.nextLine(); // 阻塞等待输入
|
||||
|
||||
// 停止服务(可选,若需优雅停机可扩展)
|
||||
System.out.println("正在停止服务...");
|
||||
scanner.close();
|
||||
System.out.println("程序已退出");
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全获取系统属性,避免空值或异常
|
||||
*/
|
||||
|
||||
BIN
src/cc/winboll/AuthCenterConsoleApp.class
Normal file
BIN
src/cc/winboll/AuthCenterConsoleApp.class
Normal file
Binary file not shown.
BIN
src/cc/winboll/LogUtils$CustomLogFormatter.class
Normal file
BIN
src/cc/winboll/LogUtils$CustomLogFormatter.class
Normal file
Binary file not shown.
BIN
src/cc/winboll/LogUtils.class
Normal file
BIN
src/cc/winboll/LogUtils.class
Normal file
Binary file not shown.
69
src/cc/winboll/LogUtils.java
Normal file
69
src/cc/winboll/LogUtils.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package cc.winboll;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.logging.ConsoleHandler;
|
||||
import java.util.logging.Formatter;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* 日志工具类,对接 Java 原生 java.util.logging,简化使用+格式化输出
|
||||
*/
|
||||
public class LogUtils {
|
||||
// 全局日志实例,绑定当前类名
|
||||
private static final Logger LOGGER = Logger.getLogger(LogUtils.class.getName());
|
||||
// 静态代码块初始化日志配置(仅执行一次)
|
||||
static {
|
||||
// 关闭父处理器,避免重复输出
|
||||
LOGGER.setUseParentHandlers(false);
|
||||
// 自定义控制台输出处理器
|
||||
ConsoleHandler consoleHandler = new ConsoleHandler();
|
||||
consoleHandler.setFormatter(new CustomLogFormatter());
|
||||
LOGGER.addHandler(consoleHandler);
|
||||
// 默认日志级别(可按需调整:ALL < FINEST < FINER < FINE < CONFIG < INFO < WARNING < SEVERE < OFF)
|
||||
LOGGER.setLevel(Level.ALL);
|
||||
consoleHandler.setLevel(Level.ALL);
|
||||
}
|
||||
|
||||
// 私有化构造,禁止实例化
|
||||
private LogUtils() {}
|
||||
|
||||
// 1. 调试日志(细粒度调试信息)
|
||||
public static void d(String tag, String msg) {
|
||||
LOGGER.fine(String.format("[%s] %s", tag, msg));
|
||||
}
|
||||
|
||||
// 2. 信息日志(常规运行信息)
|
||||
public static void i(String tag, String msg) {
|
||||
LOGGER.info(String.format("[%s] %s", tag, msg));
|
||||
}
|
||||
|
||||
// 3. 警告日志(非致命异常、潜在风险)
|
||||
public static void w(String tag, String msg) {
|
||||
LOGGER.warning(String.format("[%s] %s", tag, msg));
|
||||
}
|
||||
|
||||
// 4. 错误日志(致命异常、错误场景,支持携带异常堆栈)
|
||||
public static void e(String tag, String msg) {
|
||||
LOGGER.severe(String.format("[%s] %s", tag, msg));
|
||||
}
|
||||
public static void e(String tag, String msg, Throwable throwable) {
|
||||
LOGGER.log(Level.SEVERE, String.format("[%s] %s", tag, msg), throwable);
|
||||
}
|
||||
|
||||
// 自定义日志格式化器:统一日志输出格式
|
||||
static class CustomLogFormatter extends Formatter {
|
||||
@Override
|
||||
public String format(LogRecord record) {
|
||||
// 输出格式:[时间] [日志级别] [线程名] [TAG/类名] - 日志内容
|
||||
return String.format("[%1$tF %1$tT] [%2$s] [%3$s] %4$s - %5$s%n",
|
||||
new Date(record.getMillis()),
|
||||
record.getLevel().getName(),
|
||||
Thread.currentThread().getName(),
|
||||
record.getLoggerName(),
|
||||
formatMessage(record));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIN
src/cc/winboll/auth/AuthCenterHttpService.class
Normal file
BIN
src/cc/winboll/auth/AuthCenterHttpService.class
Normal file
Binary file not shown.
71
src/cc/winboll/auth/AuthCenterHttpService.java
Normal file
71
src/cc/winboll/auth/AuthCenterHttpService.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package cc.winboll.auth;
|
||||
|
||||
import cc.winboll.LogUtils;
|
||||
import fi.iki.elonen.NanoHTTPD;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* 轻量Http服务类(NanoHTTPD适配版,兼容Android API30、Java7)
|
||||
* 仅处理/authcenter/ping存活检测请求
|
||||
* @Author 豆包&ZhanGSKen<zhangsken@qq.com>
|
||||
* @Date 2026/01/14 02:03:00
|
||||
* @LastEditTime 2026/01/14 23:10:00
|
||||
*/
|
||||
public class AuthCenterHttpService extends NanoHTTPD {
|
||||
private static final String TAG = "AuthCenterHttpService";
|
||||
private boolean isRunning = false;
|
||||
|
||||
// 构造方法传入端口,初始化NanoHTTPD
|
||||
public AuthCenterHttpService(int port) {
|
||||
super(port);
|
||||
LogUtils.d(TAG, "构造方法调用,监听端口:" + port);
|
||||
}
|
||||
|
||||
/** 启动HTTP服务 */
|
||||
public void start() throws IOException {
|
||||
LogUtils.d(TAG, "start() 函数调用,启动HTTP服务");
|
||||
super.start(NanoHTTPD.SOCKET_READ_TIMEOUT, false);
|
||||
isRunning = true;
|
||||
LogUtils.i(TAG, "HTTP服务启动成功,端口:" + getListeningPort() + ",监听/authcenter/ping");
|
||||
}
|
||||
|
||||
/** 停止HTTP服务 */
|
||||
public void stop() {
|
||||
LogUtils.d(TAG, "stop() 函数调用,停止HTTP服务");
|
||||
if (isRunning) {
|
||||
super.stop();
|
||||
isRunning = false;
|
||||
LogUtils.i(TAG, "HTTP服务已停止");
|
||||
} else {
|
||||
LogUtils.w(TAG, "HTTP服务未运行,无需停止");
|
||||
}
|
||||
}
|
||||
|
||||
// 核心:处理所有HTTP请求,仅响应/authcenter/ping
|
||||
@Override
|
||||
public Response serve(IHTTPSession session) {
|
||||
String uri = session.getUri();
|
||||
String method = session.getMethod().name();
|
||||
LogUtils.d(TAG, "接收请求:method=" + method + ",uri=" + uri);
|
||||
|
||||
// 匹配 GET /authcenter/ping 请求
|
||||
if (Method.GET.equals(session.getMethod()) && "/authcenter/ping".equals(uri)) {
|
||||
LogUtils.d(TAG, "ping请求响应成功,返回pong");
|
||||
//return newFixedLengthResponse(Response.Status.OK, "text/plain", "PONG");
|
||||
// 替换原返回逻辑,返回JSON格式响应
|
||||
return newFixedLengthResponse(Response.Status.OK, "application/json",
|
||||
"{\"createDateTime\":" + System.currentTimeMillis() + ",\"authToken\":\"winboll_auth_6a8d2f7c9e4b3a01\",\"name\":\"cc.winboll.studio.authcenterapp.models.PingPongModel\"}");
|
||||
|
||||
} else {
|
||||
// 其他请求返回404
|
||||
LogUtils.d(TAG, "非目标请求,返回404");
|
||||
return newFixedLengthResponse(Response.Status.NOT_FOUND, "text/plain", "404 Not Found");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return isRunning;
|
||||
}
|
||||
}
|
||||
|
||||
BIN
src/cc/winboll/config/AuthConfig.class
Normal file
BIN
src/cc/winboll/config/AuthConfig.class
Normal file
Binary file not shown.
BIN
src/cc/winboll/models/PingPongModel.class
Normal file
BIN
src/cc/winboll/models/PingPongModel.class
Normal file
Binary file not shown.
38
src/cc/winboll/models/PingPongModel.java
Normal file
38
src/cc/winboll/models/PingPongModel.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package cc.winboll.models;
|
||||
|
||||
public class PingPongModel {
|
||||
private long createDateTime;
|
||||
private String authToken;
|
||||
|
||||
public PingPongModel() {}
|
||||
|
||||
public PingPongModel(long createDateTime, String authToken) {
|
||||
this.createDateTime = createDateTime;
|
||||
this.authToken = authToken;
|
||||
}
|
||||
|
||||
public long getCreateDateTime() {
|
||||
return createDateTime;
|
||||
}
|
||||
|
||||
public void setCreateDateTime(long createDateTime) {
|
||||
this.createDateTime = createDateTime;
|
||||
}
|
||||
|
||||
public String getAuthToken() {
|
||||
return authToken;
|
||||
}
|
||||
|
||||
public void setAuthToken(String authToken) {
|
||||
this.authToken = authToken;
|
||||
}
|
||||
|
||||
// 重写toString,打印对象时直接显示属性值,方便调试
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PingPongModel{" +
|
||||
"createDateTime=" + createDateTime +
|
||||
", authToken='" + authToken + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
BIN
src/cc/winboll/service/AuthService.class
Normal file
BIN
src/cc/winboll/service/AuthService.class
Normal file
Binary file not shown.
BIN
src/cc/winboll/util/AuthUtils.class
Normal file
BIN
src/cc/winboll/util/AuthUtils.class
Normal file
Binary file not shown.
Reference in New Issue
Block a user