0

I want to run -jar file from my php script, my -jar file run perfectly through commandline but i want to integrate it to my website but it is not working properly and also not provide me any error. my code is below

if (isset($_POST['Export'])) { 
  exec('java -Xmx1024M -jar C:\UploadTest-1_2.jar http://localhost:8080/packaging/Package C:\book\testbook.pdf –pass park345');
  echo 'export button clicked';
}

output is:
export button clicked but -jar not doing needful.

6
  • as you need to execute this jar file on client machine or on server? Commented Sep 12, 2011 at 14:34
  • 1
    Define "not doing needful." Is the command being executed? Test it with a simple command to make sure PHP is invoking it. You'll need to do a little debugging here to see exactly where the process is failing. The Java application might not be working, the PHP process might not have correct system permissions to run it, PHP might not be invoking the command as expected, this condition might not be reached in your PHP code, etc. Commented Sep 12, 2011 at 14:36
  • 1
    Naive qustion: is java in the PATH of the process executing PHP? If not you need to add it to the PATH Environment variable of PHP or fully qualify the java executable. Commented Sep 12, 2011 at 14:53
  • @david command is not running while debbuging php script through eclipse it haltat exec command and php have permission because all other php script expect this is running well. i cant understand why php is invoking -jar file. this command is working perfectly on cmd so there is no problem with java application. Commented Sep 12, 2011 at 15:07
  • @user940743: Your comment is unclear. Does the PHP process have permission to run the java command? Does it have permission to access the .jar file? Does it have permission to do everything else it needs to do to execute this statement? Also, Ron made a good point. Can the PHP process even find the java command? As a matter of practice, you should fully-qualify the command here. If a malicious user created an executable called java in another path then your PHP script could potentially run a different executable. Commented Sep 12, 2011 at 15:09

1 Answer 1

3
  • Is Java on the path?

Try the command with "java -version", if you don't get output, Java is not on the PATH defined within the PHP environment.

  • Is the environment locked down?

When running PHP code, one generally doesn't allow any kind of execution to take place, as people could attempt to hijack the PHP environment to place code on the server which wasn't there. This means that you will have to take into account any type of chroot'ing, acl controls, permissions, selinux, and web server configurations which make it harder to run items without a clear knowledge (that means prior configuration) that the application should be allowed to run.

Sign up to request clarification or add additional context in comments.

1 Comment

can you guide me how can I integrate Java in php to execute Java command into php program. I have tried PHP/Java Bridge but find difficulty due to lack of info. I have tried php_java.dll but it is for php4. plz guide me for php5 thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.