当.bat文件运行jar时,如何使.jar和.bat文件成为.exe

时间:2019-11-24 01:06:57

标签: java batch-file jar exe

我正在编写一个程序,然后将代码导出到.jar文件。为了使程序正常工作,我需要一个.bat文件。现在,我想将.bat和.jar融合到一个将运行.bat文件而.jar无法运行的exe文件中。谢谢。

这是我的.bat文件:

@echo off
title Test Coding Language
echo Welcome to TCL
pause 
java -jar TestCodingLanguage.jar

1 个答案:

答案 0 :(得分:0)

尝试将下面的代码保存在bat文件中。它将bat文件和jar文件打包到可执行文件中,并调用bat文件。您必须更改文件的路径:

;@echo off

;rem ----------------------------------------------------------
;rem ----------------- change the paths here -----------------
;rem ----------------------------------------------------------
;set "target_exe=packed.exe"
;set "bat_file=.\test.bat"
;set "jar_file=.\cassandra-jdbc-driver-0.6.4-shaded.jar"
;rem ----------------------------------------------------------

;for %%# in ("%bat_file%") do set "batch_file=%%~nx#"
;for %%# in ("%bat_file%") do set "bat_name=%%~nx#"
;for %%# in ("%bat_file%") do set "bat_dir=%%~dp#"

;for %%# in ("%jar_file%") do set "j_file=%%~nx#"
;for %%# in ("%jar_file%") do set "jar_name=%%~nx#"
;for %%# in ("%jar_file%") do set "jar_dir=%%~dp#"


;set "target.exe=%__cd__%%target_exe%"


;copy /y "%~f0" "%temp%\2exe.sed" >nul

;(echo()>>"%temp%\2exe.sed"
;(echo(AppLaunched=cmd.exe /c "%bat_name%")>>"%temp%\2exe.sed"
;(echo(TargetName=%target.exe%)>>"%temp%\2exe.sed"
;(echo(FILE0="%bat_name%")>>"%temp%\2exe.sed"
;(echo(FILE1="%jar_name%")>>"%temp%\2exe.sed"

;(echo([SourceFiles])>>"%temp%\2exe.sed"
;(echo(SourceFiles0=%bat_dir%)>>"%temp%\2exe.sed"
;(echo(SourceFiles1=%jar_dir%)>>"%temp%\2exe.sed"

;(echo([SourceFiles0])>>"%temp%\2exe.sed"
;(echo(%%FILE0%%=)>>"%temp%\2exe.sed"

;(echo([SourceFiles1])>>"%temp%\2exe.sed"
;(echo(%%FILE1%%=)>>"%temp%\2exe.sed"


;iexpress /n /q /m %temp%\2exe.sed

;rem del /q /f "%temp%\2exe.sed"
; exit /b 0

[Version]
Class=IEXPRESS
SEDVersion=3
[Options]
PackagePurpose=InstallApp
ShowInstallProgramWindow=0
HideExtractAnimation=1
UseLongFileName=1
InsideCompressed=0
CAB_FixedSize=0
CAB_ResvCodeSigning=0
RebootMode=N
InstallPrompt=%InstallPrompt%
DisplayLicense=%DisplayLicense%
FinishMessage=%FinishMessage%
TargetName=%TargetName%
FriendlyName=%FriendlyName%
AppLaunched=%AppLaunched%
PostInstallCmd=%PostInstallCmd%
AdminQuietInstCmd=%AdminQuietInstCmd%
UserQuietInstCmd=%UserQuietInstCmd%
SourceFiles=SourceFiles

[Strings]
InstallPrompt=
DisplayLicense=
FinishMessage=
FriendlyName=-
PostInstallCmd=<None>
AdminQuietInstCmd=
UserQuietInstCmd=
;