Sunil Kumar
Sunil Kumar

Reputation: 311

Run java class file in php code using php/javabridge

I have setup php/java bridge followed this and its working fine.

but the problem is i am unable to run a java class file in my php code.

my class file test.java is as follow

  package recommander;
  public class test
  {
     public static void main(String[] args) 
      {
          System.out.println("good");

      }
  }

and my php file as below

 <?php 
    require_once("http://localhost:8080/JavaBridge/java/Java.inc");
    $System = java("java.lang.System");
    echo $System->getProperties();
    exec("java test", $output);
    print_r($output);
?>

But when i run this php file it gives me an empty Array with following error-

Error: Could not find or load main class test

Need help.

Upvotes: 2

Views: 735

Answers (1)

Brunaldo
Brunaldo

Reputation: 66

The error you're getting is because you're trying to compile an un-compiled Java file.

Make sure you compile the test.java file in Terminal/Command Line by:

javac test.java

and then try compiling the new test.class file:

exec("java test", $output);

Upvotes: 1

Related Questions