msys2-runtime icon indicating copy to clipboard operation
msys2-runtime copied to clipboard

Java Classpath Broken

Open AntumDeluge opened this issue 1 year ago • 8 comments

I recently did a full upgrade pacman -Syyu & now I can't pass a classpath value to my Java virtual machine:

$ java -cp ./:./libs/*:./build/build_server:./build/build_server_maps:./build/build_server_script:./build/build_server_xmlconf games.stendhal.server.StendhalServer
Error: Could not find or load main class games.stendhal.server.StendhalServer
Caused by: java.lang.ClassNotFoundException: games.stendhal.server.StendhalServer

It was working the last time that I had run the command a couple days ago, before I did the update today. Note that it had probably been months since I did a system upgrade last.

Running the same command in a Windows Command Prompt does work:

>java -cp .\;libs\*;build\build_server;build\build_server_maps;build\build_server_script;build\build_server_xmlconf games.stendhal.server.StendhalServer

So it appears to be an issue with the MSYS2 console & parsing classpath string. I have not attempted a clean install yet.

AntumDeluge avatar Mar 05 '24 08:03 AntumDeluge

Just tried with a fresh install & the problem is the same.

AntumDeluge avatar Mar 05 '24 08:03 AntumDeluge

I can not suggest any proper solution but I have seen in many projects that a batch file is used to set the classpath. For example, I run batch scripts from jadx, ghidra etc. ~in msys2.~

Biswa96 avatar Mar 05 '24 09:03 Biswa96

Could you enclose the -cpargument in "$(cygpath -wp ...)" to see whether this fixes the issue?

dscho avatar Mar 06 '24 08:03 dscho

Could you enclose the -cpargument in "$(cygpath -wp ...)" to see whether this fixes the issue?

@dscho This does indeed fix it.

Is there something I can configure to force it to use cygpath -wp by default? (other than putting it in a script)

AntumDeluge avatar Mar 06 '24 15:03 AntumDeluge

Is there something I can configure to force it to use cygpath -wp by default? (other than putting it in a script)

That would be detrimental.

The idea of MSYS2's path conversion is to guess how to handle command-line arguments passed between MSYS and non-MSYS programs. Since this is an ambiguous task, the heuristic is necessarily wrong at times. In your case, I think that the heuristic would have been correct if the second path element had been an absolute path.

dscho avatar Mar 09 '24 09:03 dscho

The idea of MSYS2's path conversion is to guess how to handle command-line arguments passed between MSYS and non-MSYS programs...

Something must have changed with a recent update because it used to parse the classpath parameter correctly without the need to enclose it in a call to cygpath.

AntumDeluge avatar Mar 13 '24 08:03 AntumDeluge

@AntumDeluge commented 1 hour ago:

The idea of MSYS2's path conversion is to guess how to handle command-line arguments passed between MSYS and non-MSYS programs...

Something must have changed with a recent update because it used to parse the classpath parameter correctly without the need to enclose it in a call to cygpath.

It would be nice if JRE for Windows would be taught to understand both Windows and *nix path formats. That would eliminate the need to use guessing.

@AntumDeluge, in the meantime you could use some java.exe wrapper script put into your PATH (somewhere before the original binary) which could do the conversion itself... Just a thought.

sskras avatar Mar 13 '24 10:03 sskras

in the meantime you could use some java.exe wrapper script put into your PATH (somewhere before the original binary) which could do the conversion itself... Just a thought.

Yes, that sounds like a good solution. I said before that I didn't want to put it in a script [that was dedicated to a single command]. But that was nonsense, because putting it in a universal wrapper will do exactly what I want.

AntumDeluge avatar Mar 13 '24 11:03 AntumDeluge