0

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...

2
  • P.S. This question would seem equally appropriate here, on StackOverflow, or on ServerFault. Is there any reason to prefer one over the other (for this question---I use StackOverflow loads for more obvious programming questions), other than the likely community who will read it? Jun 26, 2014 at 10:55
  • This meta-question somewhat answers that: meta.serverfault.com/questions/2602 Jun 26, 2014 at 10:58

1 Answer 1

0

It was a bug in the JDK/JRE fixed in 7u10 (I was using 7u9): see the 7u10 release notes and the bug report.

I should have looked more carefully about what the symptoms were telling me: it is Java ('pre-processing') that does the wildcard expansion, not Windows, and it was doing the expansion but then presumably omitting the semicolons or similar so that Java then saw -cp a.jar b.jar [other stuff] instead of -cp a.jar;b.jar;[...];z.jar [class to run].

As mentioned in the bug report, apparently a workaround is to use -cp "MyLibFolder/*;" (i.e., include a trailing ; with the wildcard).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .