How to transfer all jar files to a directory in my batch file

I created a run.bat batch file:

set CLASSPATH=%CLASSPATH%.;.\Jars\app.jar;.\Jars\a.jar;.\Jars\b.jar;.\Jars\c.jar;.\Jars\d.jar;
java mypackage.mysubpackage.Start
pause

I saved all the class files associated with my application in "app.jar" and Startis the class from which the application starts execution. I have this file "run.bat" and all the banks that my "app.jar" wants to transfer in the same directory.
I saved all these banks in the "Jars" folder and refer to it in my "run.bat" file, as shown above. However, in order to reference each jar file using my "run.bat", I need to specify the path as ". \ Jars \ jarname.jar". When I use ". \ Jars \ *. Jar", banks do not reference "run.bat". Can someone provide him an alternative?

+5
source share
3 answers

In fact, you only did half the work using * .jar. You will also need to pass them as a java classpath: java -cp $CLASSPATH mypackage.mysubpackage.Start. (in windows, I think the variable usage in the script is% CLASSPATH%)

Then edit: take a look at BigMike's comments on your subject. If you are using the java version <1.6, you may need to use a loop to create the full% CLASSPATH%, including each full jar name, because I assume that the Windows shell does not make extensions , as do * nix systems.

+2
source

You can try using a loop to create a class path in batch mode, for example 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
+2
source

-, http://docs.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html

:

" , *, . JAR foo, foo; foo/* foo/; foo. , foo JAR foo . . , foo/ JAR foo, foo/bar, foo/baz .."

, :

set CLASSPATH=%CLASSPATH%.;.\Jars;.\Jars\*

set CLASSPATH=%CLASSPATH%.;.\Jars;.\Jars\*.jar

\Jars

+1

All Articles