I have a PHP-script originally developed on Ubuntu, which now has to run on a Windows machine, executing a java program like this:

```
exec("java -jar {$filename}");
// Process output

```

This does not work as expected on Windows. I already found out, that although I can use `java -version` from the command prompt I can't use it in `exec()`, i.e. the problem is java can not be found.

I have a workaround in place, pointing to java.exe using the complete path to `C:\Program Files\Java\...\java.exe` if the script runs on Windows. Unfortunately though this is hardcoded to the path on the current machine, which might change or vary on a different system, e.g. when installing Java to a different location or a different version (JRE/JDK/6/7) is installed.

**How do I call Java on Windows without having to refer to the exact location of java.exe?**