I have a java application launched by a .cmd file. I want to set the classpath of the application through this batch, all the needed jars are into a lib folder.
Here is what I tried :
set _classpath=.
for %%i in (%1/lib/*.*) do ( set _classpath=%_classpath%;%%i )
Surprisingly, it seems that it does not act as expected. Let's say there is 3 jar in the lib folder :
Here is what happens :
Obviously, what I am looking to get is
Any idea ?
Thanks and regards,
Place this at the top of your batch file:
setlocal enabledelayedexpansion
Then inside the for loop, replace %_classpath%
with !_classpath!
Without delayed expansion enabled, %_classpath%
gets expanded once, at the beginning of your for loop.
[Edit] In response to a comment, here is a full code-listing
@echo off
setlocal enabledelayedexpansion
set _classpath=.
for %%i in (%1/lib/*.*) do (
set _classpath=!_classpath!;%%i
)
echo %_classpath%
pause
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With