Repository navigation
Expand file tree
/
Copy pathdeploy.bat
More file actions
87 lines (69 loc) · 2.79 KB
/
Copy pathdeploy.bat
File metadata and controls
87 lines (69 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
@echo off
setlocal
set "TOMCAT=C:\Program Files (x86)\Apache Software Foundation\Tomcat 10.1"
set "CATALINA_HOME=%TOMCAT%"
set "CATALINA_BASE=%TOMCAT%"
set "APP=%TOMCAT%\webapps\LocalHelp"
set "URL=http://localhost:8080/LocalHelp/"
if defined JAVA_HOME goto :java_ready
for /f "delims=" %%J in ('where java 2^>nul') do if not defined JAVA_EXE set "JAVA_EXE=%%J"
if not defined JAVA_EXE goto :java_missing
for %%J in ("%JAVA_EXE%") do set "JAVA_HOME=%%~dpJ.."
:java_ready
call build.bat
if errorlevel 1 exit /b 1
if not exist "%TOMCAT%\webapps" goto :tomcat_missing
if not exist "%TOMCAT%\bin\startup.bat" goto :tomcat_missing
if not exist "%JAVA_HOME%\bin\java.exe" goto :java_missing
if exist "%APP%" rmdir /s /q "%APP%"
mkdir "%APP%"
xcopy "WebContent\*" "%APP%\" /E /I /Y >nul
if defined UPLOAD_BACKUP if exist "%UPLOAD_BACKUP%\*" xcopy "%UPLOAD_BACKUP%\*" "%APP%\uploads\" /E /I /Y >nul
dir /b "%APP%\WEB-INF\lib\mysql-connector-j-*.jar" >nul 2>&1
if errorlevel 1 goto :deploy_failed
if not exist "%APP%\WEB-INF\web.xml" goto :deploy_failed
if not exist "%APP%\WEB-INF\classes\com\localhelp\servlet\AuthServlet.class" goto :deploy_failed
echo.
echo LocalHelp deployed to:
echo %APP%
echo.
netstat -ano | findstr /r /c:":8080 .*LISTENING" >nul
if not errorlevel 1 goto :check_existing_server
echo Starting Tomcat...
call "%TOMCAT%\bin\startup.bat"
if errorlevel 1 goto :startup_failed
echo Waiting for LocalHelp to become available...
powershell -NoProfile -ExecutionPolicy Bypass -Command "$deadline = (Get-Date).AddSeconds(20); while ((Get-Date) -lt $deadline) { try { Invoke-WebRequest -UseBasicParsing -Uri '%URL%' -TimeoutSec 1 | Out-Null; exit 0 } catch { Start-Sleep -Milliseconds 500 } }; exit 1"
if errorlevel 1 goto :startup_failed
:check_existing_server
powershell -NoProfile -ExecutionPolicy Bypass -Command "try { Invoke-WebRequest -UseBasicParsing -Uri '%URL%' -TimeoutSec 1 | Out-Null; exit 0 } catch { exit 1 }"
if errorlevel 1 goto :port_conflict
:server_ready
echo.
echo LocalHelp is starting at:
echo %URL%
start "" "%URL%"
endlocal
exit /b 0
:tomcat_missing
echo Tomcat webapps directory not found at:
echo %TOMCAT%\webapps
exit /b 1
:java_missing
echo Java was not found on PATH and JAVA_HOME is not set.
echo Install JDK 21 or set JAVA_HOME to your JDK installation.
exit /b 1
:startup_failed
echo LocalHelp could not be reached at %URL%.
echo Check the Tomcat logs under:
echo %TOMCAT%\logs
exit /b 1
:port_conflict
echo Port 8080 is already in use by another application.
echo Stop that application or change Tomcat's port before running deploy.bat again.
exit /b 1
:deploy_failed
echo Deployment failed because one or more required runtime files are missing.
echo Check the deployed application at:
echo %APP%
exit /b 1