Blog : Problem executing .jar in php

Problem executing .jar in php

I am trying to run a simple .jar file in php. The .jar is supposed to read a file called test.txt and write a file called test2.txt.

After creating the jar, I execute java -jar "C:\wamp\www\Sistem\Sistem\dist\Sistem.jar" in cmd and it works just fine, the test2.txt is modified, but in php this doesn't happen. Here's the source

C:\wamp\www\Sistem\index.php:

< ? php
echo exec('java -jar "C:\wamp\www\Sistem\Sistem\dist\Sistem.jar"');
? >
I just access http://localhost/Sistem/, but the test2.txt file does not modify. I really need help, thanks !

php jar command execute
share|improve this question
edited Apr 18 '11 at 19:45

RobertPitt
   
Sistem is spelled System ! –  RobertPitt Apr 18 '11 at 19:46
   
Try \\` instead of \` in the path. –  cweiske Apr 18 '11 at 20:13
   
I haven't run php on Windows, but this kind of thing often requires some care with file permissions. The user owning the web server process will probably need write permissions on test2.txt. –  grossvogel Apr 18
Try using absolute path to java binary:

shell_exec('"c:/program files/oracle/jdk/bin/java.exe" -jar "d:/path/to/jar.jar"');
If it will work, that means php runs with different %PATH% environment variable.