@echo off setlocal enabledelayedexpansion echo =============================================== echo Java Application Build for Windows echo =============================================== echo. echo [1] Checking Java environment... java -version >nul 2>&1 if errorlevel 1 ( echo ERROR: Java not found in PATH echo Please install Java and add to PATH exit /b 1 ) javac -version >nul 2>&1 if errorlevel 1 ( echo ERROR: Java compiler not found echo Please install JDK exit /b 1 ) echo Java environment OK echo [2] Cleaning previous build... if exist "WebContent\WEB-INF\classes" rmdir /s /q "WebContent\WEB-INF\classes" echo Previous build cleaned echo [3] Creating directories... if not exist "WebContent\WEB-INF\classes" mkdir "WebContent\WEB-INF\classes" if not exist "WebContent\WEB-INF\lib" mkdir "WebContent\WEB-INF\lib" if not exist "logs" mkdir "logs" echo Directories created echo [4] Checking libraries... set SERVLET_JAR1=WebContent\WEB-INF\lib\javax.servlet-api-4.0.1.jar set SERVLET_JAR2=WebContent\WEB-INF\lib\servlet-api.jar if not exist "%SERVLET_JAR1%" if not exist "%SERVLET_JAR2%" ( echo ERROR: Servlet API JAR not found echo Need: %SERVLET_JAR1% or %SERVLET_JAR2% exit /b 1 ) echo Libraries OK echo [5] Setting classpath... set CLASSPATH=src;WebContent\WEB-INF\lib\* echo Classpath: %CLASSPATH% echo [6] Finding Java files... if exist java_sources.tmp del java_sources.tmp set java_count=0 for /r src %%f in (*.java) do ( echo %%f >> java_sources.tmp set /a java_count+=1 ) if %java_count% equ 0 ( echo WARNING: No Java files found ) else ( echo Found %java_count% Java files ) echo [7] Compiling Java files... if exist java_sources.tmp ( javac -encoding UTF-8 -source 1.7 -target 1.7 -d WebContent\WEB-INF\classes -cp "%CLASSPATH%" @java_sources.tmp if errorlevel 1 ( echo ERROR: Compilation failed del java_sources.tmp exit /b 1 ) del java_sources.tmp echo Compilation completed ) echo [8] Copying resources... set resource_count=0 for /r src %%f in (*.xml *.properties *.sql) do ( set source_file=%%f set relative_path=!source_file:%CD%\src\=! set target_file=WebContent\WEB-INF\classes\!relative_path! for %%d in ("!target_file!") do ( if not exist "%%~dpd" mkdir "%%~dpd" 2>nul ) copy "!source_file!" "!target_file!" >nul 2>&1 if not errorlevel 1 set /a resource_count+=1 ) echo Copied %resource_count% resource files echo. echo =============================================== echo Build completed successfully! echo =============================================== echo Classes: WebContent\WEB-INF\classes\ echo Libraries: WebContent\WEB-INF\lib\ echo Logs: logs\ echo. endlocal