0

I am trying to execute a java class file from php using the exec method. However, i get the following error.

I have set chmod 777 to the java class file so i suppose permission is not an issue.

For some reason it is not able to find it ?

I can run the java class file from the terminal using the java command without any problem

Error:

Error: Could not find or load main class .var.www.redbutton.readBashScript.class


<?php

exec('java /var/www/redbutton/readBashScript.class');

?>

and

<?php

exec('java /var/www/redbutton/readBashScript');

?>

1 Answer 1

1

The java exec does not work like that.

You need not pass the file to "execute", but the class which is why you get an error.

You must do:

java -cp /var/www/redbutton readBashScript

But:

  • /var/www/redbutton must be a classpath directory, where your .class reside. Java will by default try to find classes in the current directory, which explains why it work in the console.
  • readBashScript must be the name of a class containing a main method.
Sign up to request clarification or add additional context in comments.

Comments

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.