1

I'm attempting to run a small Java class from within a PHP script. It works as expected on Linux, but when the same script is executed on Windows I receive:

Could not find or load main class JDBCProxy

Here's the relevant PHP:

$classpath = join(PATH_SEPARATOR, array(
    dirname(__FILE__).DIRECTORY_SEPARATOR.'JDBCProxy',
    dirname(__FILE__).DIRECTORY_SEPARATOR.'JDBCProxy'.DIRECTORY_SEPARATOR.'libs'.DIRECTORY_SEPARATOR.'json-simple-1.1.1.jar',
));

$cmd = sprintf("java -cp '%s' JDBCProxy", $classpath);

...

$process = proc_open($cmd, $descriptorspec, $pipes);

The output of sprintf is

java -cp 'C:\worker\lib\DB\JDBCProxy;C:\worker\lib\DB\JDBCProxy\libs\json-simple-1.1.1.jar' JDBCProxy

When run directly from the command line, this works as expected. Why isn't Java able to locate the class when run from the context of PHP?

Charlie Schliesser
  • 7,851
  • 4
  • 46
  • 76

1 Answers1

1

For Windows, use double quotes (") instead of single ones (').

See Including all the jars in a directory within the Java classpath for Java specifics and this answer for Windows' treatment of single quotes.

Adam Kotwasinski
  • 4,377
  • 3
  • 17
  • 40
  • Wow. Thank you, friend. It was made all the more confusing that it worked in the command prompt with single quotes, but double quotes within the context of PHP does it. – Charlie Schliesser Nov 02 '17 at 21:08