OCR/re-build-start.bat
2025-05-13 11:07:14 +08:00

83 lines
2.6 KiB
Batchfile
Raw Permalink 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.

@echo off
chcp 65001
title OCR监控工具-编译运行
echo [%date% %time%] 正在启动OCR监控工具编译和运行...
REM 停止现有程序
echo [%date% %time%] 正在停止现有程序...
taskkill /F /FI "WINDOWTITLE eq OCR监控工具" /T >nul 2>&1
taskkill /F /IM java.exe /FI "WINDOWTITLE eq OCR监控工具" >nul 2>&1
timeout /t 2 /nobreak >nul
REM 检查Java是否安装
echo [%date% %time%] 检查Java环境...
java -version
if errorlevel 1 (
echo [%date% %time%] 错误: 未检测到Java请安装Java 11或更高版本
pause
exit /b 1
)
REM 检查Maven是否安装
echo [%date% %time%] 检查Maven环境...
mvn -v
if errorlevel 1 (
echo [%date% %time%] 错误: 未检测到Maven请安装Maven
pause
exit /b 1
)
REM 检查Tesseract是否安装
echo [%date% %time%] 检查Tesseract环境...
if not exist "C:\Program Files\Tesseract-OCR\tesseract.exe" (
echo [%date% %time%] 错误: 未检测到Tesseract-OCR请安装Tesseract-OCR
pause
exit /b 1
)
REM 设置Tesseract环境变量
set "TESSDATA_PREFIX=%~dp0tessdata"
echo [%date% %time%] 设置TESSDATA_PREFIX=%TESSDATA_PREFIX%
REM 确保目录存在
echo [%date% %time%] 检查并创建必要的目录...
if not exist "ocr_results" mkdir ocr_results
if not exist "test_images" mkdir test_images
if not exist "ocr_images" mkdir ocr_images
if not exist "split_images" mkdir split_images
if not exist "tessdata" mkdir tessdata
REM 确保结果文件存在并包含有效的JSON数组
echo [%date% %time%] 初始化结果文件...
echo [] > ocr_results\current_results.json
echo [] > ocr_results\all_results.json
echo. > ocr_results\processed_files.txt
REM 编译项目
echo [%date% %time%] 正在编译项目...
call mvn clean package
REM 检查编译是否成功
if errorlevel 1 (
echo [%date% %time%] 错误: 项目编译失败,请检查错误信息
pause
exit /b 1
)
REM 检查编译后的jar文件
if not exist "target\image-ocr-monitor-1.0-SNAPSHOT-jar-with-dependencies.jar" (
echo [%date% %time%] 错误: 编译后的jar文件未找到
pause
exit /b 1
)
REM 运行程序
echo [%date% %time%] 正在启动程序...
echo [%date% %time%] 程序日志将在新窗口中显示...
REM 直接在新窗口中启动程序
start "OCR监控工具" cmd /k "chcp 65001 && echo [%date% %time%] OCR监控工具启动中... && java -Dfile.encoding=UTF-8 -Dfile.client.encoding=UTF-8 -Dtessdata.path="%~dp0tessdata" -Duser.language=zh -Duser.country=CN -jar target\image-ocr-monitor-1.0-SNAPSHOT-jar-with-dependencies.jar"
echo [%date% %time%] 程序编译完成并已启动,此窗口可以关闭
timeout /t 5