简体   繁体   中英

How to embed jar file in Windows batch file?

I'd like to do something similar to https://coderwall.com/p/ssuaxa/how-to-make-a-jar-file-linux-executable in Windows.

Context: I'm writing a protoc add-on which requires one and only one executable file being used.

I've created a stub.bat file with the following contents:

@ECHO OFF
"C:\Program Files\Java\jdk1.8.0_161\bin\java" -jar %~dp0%0 %*

and followed similar instructions as what's described for Unix, but upon running the generated batch file, I'm seeing:

Hello, World
'□' is not recognized as an internal or external command, operable program or batch file.

The "Hello, World" is an indication that what I'm doing is actually working. But how can the garbage at the end be eliminated?

End stub.bat with:

exit /b

From https://ss64.com/nt/exit.html :

Syntax
      EXIT [/B] [exitCode]

Key
    /B        When used in a batch script, this option will exit 
              only the script (or subroutine) but not CMD.EXE

   exitCode   Sets the %ERRORLEVEL% to a numeric number.
              If quitting CMD.EXE, set the process exit code no.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM