I have created a batch file "run.bat":
set CLASSPATH=%CLASSPATH%.;.\Jars\app.jar;.\Jars\a.jar;.\Jars\b.jar;.\Jars\c.jar;.\Jars\d.jar;
java mypackage.mysubpackage.Start
pause
I have kept all the class files related to my application in "app.jar" and
Start
is the class from where the application begins execution. I have this "run.bat" file and all the jars that my "app.jar" wants to refer in the same directory.
I kept all these jars in the "Jars" folder and referring to it in my "run.bat" file as shown above. However, to refer to each and every jar file by my "run.bat" I need to specify the path as ".\Jars\jarname.jar". When I am using ".\Jars\*.jar" the jars are not referred by "run.bat".
Can anyone provide an alternative for it?
Actually you have done only half the work using *.jar. You also need to pass them to java as the classpath: java -cp $CLASSPATH mypackage.mysubpackage.Start
. (on windows I think the use of a variable in a script is %CLASSPATH%)
Later edit: take a look at BigMike's comments on your question. If you're using a java version < 1.6, you might need to use a loop to build a complete %CLASSPATH% including each jar's full name individually, because I'm guessing that Windows' shell doesn't do expansions just like *nix systems.
You can try to use for loop to create class path in batch, such as the below.
@echo off
for %%jar in (.\Jars\*.jar) do call :add_jar %%jar
java -cp %CLASSPATH%;%JARS% mypackage.mysubpackage.Start
pause
exit /b
:add_jar
set JARS=%JARS%;%1
exit /b
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