简体   繁体   中英

How to run any jar file by a .bat file?

My command is java -jar my-jar-1.0.0-SNAPSHOT.jar

I want to create a bat file to run this command irrespective of the SNAPSHOT version. This jar is located in the D drive I have written this:

@ECHO ON
D:
cd "D:\Code\target"
java -jar my-jar-1.0.0-SNAPSHOT.jar

But the thing is when my SNAPSHOT version changes, again I have to edit the bat file. I there any command or way so that whatever the version is the bat file runs.

java -jar my-jar-<any-version>-SNAPSHOT.jar

or

java -jar my-jar-<any-SNAPSHOT>.jar

You could try using a for loop — in :

for %I in ("D:\Code\target\my-jar-*-SNAPSHOT.jar") do @(pushd "%~dpI." && (java -jar "%~nxI" & popd))

Double the % -signs in a :

for %%I in ("D:\Code\target\my-jar-*-SNAPSHOT.jar") do @(
    pushd "%%~dpI." && (
        java -jar "%%~nxI"
        popd
    )
)

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