windows 使用 xcopy 命令复制文件,每个target下的jar包复制到一起

本文档详细记录了一个批处理脚本,展示了如何将多个Java应用的jar包从各自构建目录复制到统一的jar文件夹,便于管理和部署。脚本涉及bgmt、dataDeal、gateway、registry和smsg等多个模块。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

将所有jar包复制到一个地方

@echo off
echo "数据复制.....start...."  
echo.  
 

set "ccpth=%~dp0"

echo "begin xcoopy bgmt-0.0.1-SNAPSHOT.jar"
xcopy %ccpth%bgmt\build\libs\bgmt-0.0.1-SNAPSHOT.jar %ccpth%jar\bgmt\app.jar  /y

echo "begin xcoopy dataDeal-0.0.1-SNAPSHOT.jar"
xcopy %ccpth%dataDeal\build\libs\dataDeal-0.0.1-SNAPSHOT.jar    %ccpth%jar\dataDeal\app.jar /y

echo "begin xcoopy gateway.jar"
xcopy %ccpth%gateway\build\libs\gateway.jar    %ccpth%jar\gateway\app.jar /y

echo "begin xcoopy registry-0.0.1-SNAPSHOT.jar"
xcopy %ccpth%registry\build\libs\registry-0.0.1-SNAPSHOT.jar    %ccpth%jar\registry\app.jar /y

echo "begin xcoopy smsg-0.0.1-SNAPSHOT.jar"
xcopy %ccpth%smsg\build\libs\smsg-0.0.1-SNAPSHOT.jar    %ccpth%jar\smsg\app.jar /y

echo "begin xcoopy tmls-0.0.1-SNAPSHOT.jar"
xcopy %ccpth%tmls\build\libs\tmls-0.0.1-SNAPSHOT.jar    %ccpth%jar\tmls\app.jar /y

echo "数据复制.....end...." 

pause

@echo off
echo "数据复制.....start...."  
echo.  

set "ccpth=%~dp0"


echo "begin xcopy tzwy-gateway "
xcopy %ccpth%tzwy-gateway\target\tzwy-gateway.jar %ccpth%bin\jar\   /Y /L

echo "begin xcopy tzwy-auth "
xcopy %ccpth%tzwy-auth\target\tzwy-auth.jar  %ccpth%bin\jar\  /Y /L

echo "begin xcopy tzwy-visual "
xcopy %ccpth%tzwy-visual\tzwy-monitor\target\tzwy-visual-monitor.jar   %ccpth%bin\jar\   /Y /L

echo "begin xcopy tzwy-modules-system "
xcopy %ccpth%tzwy-modules\tzwy-system\target\tzwy-modules-system.jar  %ccpth%bin\jar\   /Y /L

echo "begin xcopy tzwy-modules-file "
xcopy %ccpth%tzwy-modules\tzwy-file\target\tzwy-modules-file.jar  %ccpth%bin\jar\   /Y /L

echo "begin xcopy tzwy-modules-job "
xcopy %ccpth%tzwy-modules\tzwy-job\target\tzwy-modules-job.jar  %ccpth%bin\jar\   /Y /L

echo "begin xcopy tzwy-modules-gen "
xcopy %ccpth%tzwy-modules\tzwy-gen\target\tzwy-modules-gen.jar  %ccpth%bin\jar\   /Y /L

echo "数据复制.....end...." 

pause

@echo off setlocal enabledelayedexpansion :: Set console title for better visibility title Launch4j Packager - %DATE% %TIME% :: Check if Launch4j is installed where launch4jc >nul 2>&1 if %ERRORLEVEL% neq 0 ( echo [ERROR] launch4jc not found in PATH. echo Please install Launch4j and add it to your system PATH. pause exit /b 1 ) :: User input with defaults set SOURCE_JAR_DIR=D:\1-information\source set TARGET_EXE_DIR=D:\1-information\target\aaa set OUTPUT_NAME=MyApp :: Normalize paths for %%i in ("%SOURCE_JAR_DIR%") do set SOURCE_JAR_DIR=%%~fi for %%i in ("%TARGET_EXE_DIR%") do set TARGET_EXE_DIR=%%~fi :: Verify source directory exists if not exist "%SOURCE_JAR_DIR%" ( echo [ERROR] Source directory does not exist: %SOURCE_JAR_DIR% pause exit /b 1 ) :: Find main JAR file set MAIN_JAR= set JAR_COUNT=0 for %%f in ("%SOURCE_JAR_DIR%\*.jar") do ( set /a JAR_COUNT+=1 if !JAR_COUNT! equ 1 set MAIN_JAR=%%~nxf ) if %JAR_COUNT% equ 0 ( echo [ERROR] No JAR files found in: %SOURCE_JAR_DIR% pause exit /b 1 ) else if %JAR_COUNT% gtr 1 ( echo [WARNING] Multiple JARs found. Using first one: %MAIN_JAR% ) :: JRE detection with improved logic set BUNDLE_JRE=false set JRE_PATH= :: Check for JDK 17+ structure if defined JAVA_HOME ( if exist "%JAVA_HOME%\jre\bin\java.exe" ( set JRE_PATH=%JAVA_HOME%\jre set BUNDLE_JRE=true ) else if exist "%JAVA_HOME%\bin\java.exe" ( set JRE_PATH=%JAVA_HOME% set BUNDLE_JRE=true ) ) :: Additional JRE search locations if "%BUNDLE_JRE%"=="false" ( for %%d in ( "%ProgramFiles%\Java\jre*" "%ProgramFiles(x86)%\Java\jre*" ) do ( if exist "%%d\bin\java.exe" ( set JRE_PATH=%%d set BUNDLE_JRE=true goto :jre_found ) ) ) :jre_found if "%BUNDLE_JRE%"=="true" ( echo [INFO] Found JRE at: %JRE_PATH% ) else ( echo [WARNING] No JRE found. EXE will require Java 17+ to be installed. ) :: Create temp working directory with timestamp set TIMESTAMP=%DATE:~-4%%DATE:~3,2%%DATE:~0,2%_%TIME:~0,2%%TIME:~3,2% set TEMP_DIR=%TEMP%\%OUTPUT_NAME%_%TIMESTAMP% if exist "%TEMP_DIR%" ( echo [INFO] Cleaning previous temp directory... rd /s /q "%TEMP_DIR%" ) echo [INFO] Creating temp directory: %TEMP_DIR% mkdir "%TEMP_DIR%" if not exist "%TEMP_DIR%" ( echo [ERROR] Failed to create temp directory pause exit /b 1 ) :: Copy JAR to temp directory echo [INFO] Copying %MAIN_JAR%... copy "%SOURCE_JAR_DIR%\%MAIN_JAR%" "%TEMP_DIR%\" >nul || ( echo [ERROR] Failed to copy JAR file goto cleanup ) :: Copy dependencies if they exist if exist "%SOURCE_JAR_DIR%\lib" ( echo [INFO] Copying dependencies... mkdir "%TEMP_DIR%\lib" robocopy "%SOURCE_JAR_DIR%\lib" "%TEMP_DIR%\lib" /E /NFL /NDL /NJH /NJS >nul if %ERRORLEVEL% gtr 7 ( echo [WARNING] Some dependencies may not have copied properly ) ) :: Improved JRE bundling with error handling if "%BUNDLE_JRE%"=="true" ( echo [INFO] Bundling JRE environment (please wait)... mkdir "%TEMP_DIR%\jre" :: Copy critical directories first for %%d in ("bin" "lib" "conf") do ( if exist "%JRE_PATH%\%%d" ( echo Copying %%d directory... robocopy "%JRE_PATH%\%%d" "%TEMP_DIR%\jre\%%d" /E /NFL /NDL /NJH /NJS >nul if %ERRORLEVEL% gtr 7 ( echo [ERROR] Failed to copy %%d directory goto cleanup ) ) ) :: Copy remaining files echo Copying remaining JRE files... robocopy "%JRE_PATH%" "%TEMP_DIR%\jre" /E /XF *.tmp /NFL /NDL /NJH /NJS >nul if %ERRORLEVEL% gtr 7 ( echo [WARNING] Some JRE files may not have copied ) echo [INFO] JRE bundled successfully ) :: Generate Launch4j config echo [INFO] Generating configuration... ( echo <?xml version="1.0" encoding="UTF-8"?> echo <launch4jConfig> echo <dontWrapJar>false</dontWrapJar> echo <headerType>gui</headerType> echo <jar>%MAIN_JAR%</jar> echo <outfile>%OUTPUT_NAME%.exe</outfile> echo <errTitle>%OUTPUT_NAME% Error</errTitle> echo <cmdLine></cmdLine> echo <chdir>.</chdir> echo <priority>normal</priority> echo <downloadUrl>https://www.oracle.com/java/technologies/downloads/</downloadUrl> echo <supportUrl></supportUrl> echo <stayAlive>false</stayAlive> echo <restartOnCrash>false</restartOnCrash> echo <manifest></manifest> echo <icon></icon> echo <jre> echo <path>jre</path> echo <bundled>%BUNDLE_JRE%</bundled> echo <minVersion>17</minVersion> echo <maxVersion></maxVersion> echo <jdkPreference>preferJre</jdkPreference> echo <runtimeBits>64/32</runtimeBits> echo </jre> echo <versionInfo> echo <fileVersion>1.0.0</fileVersion> echo <txtFileVersion>1.0</txtFileVersion> echo <fileDescription>%OUTPUT_NAME%</fileDescription> echo <copyright>Copyright © %date:~-4%</copyright> echo <productVersion>1.0.0</productVersion> echo <txtProductVersion>1.0</txtProductVersion> echo <productName>%OUTPUT_NAME%</productName> echo <companyName></companyName> echo <internalName>%OUTPUT_NAME%</internalName> echo <originalFilename>%OUTPUT_NAME%.exe</originalFilename> echo </versionInfo> echo </launch4jConfig> ) > "%TEMP_DIR%\config.xml" || ( echo [ERROR] Failed to create config file goto cleanup ) :: Execute Launch4j with error handling echo [INFO] Generating EXE file... cd /d "%TEMP_DIR%" call launch4jc config.xml set EXIT_CODE=%ERRORLEVEL% if %EXIT_CODE% neq 0 ( echo [ERROR] EXE generation failed (Error: %EXIT_CODE%) echo Possible solutions: echo 1. Ensure Launch4j version supports JDK 17+ echo 2. Check if JAR file is valid echo 3. Verify sufficient disk space goto cleanup ) :: Create output directory structure if not exist "%TARGET_EXE_DIR%" ( echo [INFO] Creating target directory... mkdir "%TARGET_EXE_DIR%" || ( echo [ERROR] Failed to create target directory goto cleanup ) ) :: Copy results echo [INFO] Copying results to target location... copy "%TEMP_DIR%\%OUTPUT_NAME%.exe" "%TARGET_EXE_DIR%\" >nul || ( echo [ERROR] Failed to copy EXE file goto cleanup ) robocopy "%TEMP_DIR%" "%TARGET_EXE_DIR%\%OUTPUT_NAME%" /E /NFL /NDL /NJH /NJS >nul if %ERRORLEVEL% gtr 7 ( echo [WARNING] Some files not copied to final package ) :: Final success message echo. echo ===== PACKAGING SUCCESSFUL ===== echo. echo Main EXE: "%TARGET_EXE_DIR%\%OUTPUT_NAME%.exe" echo Full package: "%TARGET_EXE_DIR%\%OUTPUT_NAME%\" echo. if "%BUNDLE_JRE%"=="true" ( echo JRE was included (package size may be large) ) else ( echo Note: JRE not included - users need Java 17+ installed ) echo. :cleanup :: Only cleanup on success if %EXIT_CODE% equ 0 ( echo [INFO] Cleaning up temporary files... rd /s /q "%TEMP_DIR%" 2>nul ) else ( echo [INFO] Preserving temp files for debugging: %TEMP_DIR% ) pause exit /b %EXIT_CODE% 中Bundling JRE environment999999999...未打印就出现闪退了
最新发布
07-11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值