I'm using a Windows batch file to launch a Java program, using wildcard expansion to set a load of JAR files on the classpath similar to the below:
java -cp "MyLibFolder\*" com.stupid.StupidProgram parm1
(The quotes are needed for Windows as per this StackOverflow question.)
This works perfectly on my Win 7 x64 Home Premium machine at home, and used to work fine on my work PC (Win 7 x64 Enterprise). However, it now throws an error on my work PC saying that it's trying to find the main class within one of the JARs in the classpath expansion.
If MyLibFolder contains a.jar, b.jar, ...., z.jar
, the error is that it can't find a main class in b.jar
.
After some experimenting, it appears that it is acting as though the double quotes have been removed i.e. it is acting on
java -cp a.jar b.jar c.jar [...] z.jar com.stupid.StupidProgram parm1
instead of
java -cp "a.jar b.jar c.jar [...] z.jar" com.stupid.StupidProgram parm1
Can anyone tell me why this might be happening on one Win 7 PC and not the other? (The batch file is identical, shared via version control.)
Edit: Aha! If I run it via cmd.exe
in the Windows SysWOW64
folder (instead of the system32
one I get when running cmd
by default or---it would seem---double-clicking the batch file), it works. My understanding (e.g., from this Microsoft Answers question) is that that's running the 32-bit cmd
instead of the default 64-bit one (though the exe's locations seem to scream the contrary!). I guess I still need to understand why this works (why should this relate to quoting?), and why there are differences between the two PCs.
Edit 2: Actually, running it via the 32-bit cmd.exe
caused other problems in the Java that was being executed: see this SVNKit thread. (I guess it caused some sort of filesystem permissions issue.) I've had to work round it by changing the batch file to have a manual expansion of all the lib JARs. I'd still like to understand the problem though...