Problem calling Java from PHP script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eldushyant
Forum Newbie
Posts: 1
Joined: Thu Apr 29, 2010 12:31 am

Problem calling Java from PHP script

Post by eldushyant »

I am working on windows. I am running PHP (5.1.3) scripts on Tomcat using PHP/Java bridge. Here is my simple code

Code: Select all

//test.php
<?php
require_once("java\Java.inc");
$systemInfo = new Java("Test");
print $systemInfo->foo();
?>

Code: Select all

//test.java
class Test
{
 public void foo()
 {
  System.out.println("hello php");
 }
}
Test.class is in the same folder as test.php. But the php file is not able to locate the test class and I get the following error -

Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: CreateInstance failed: new Test.

If I use a standard class like below. It works -

Code: Select all

<?php
require_once("java\Java.inc");
$systemInfo = new Java("java.lang.System");
print "Total seconds since January 1, 1970: 
".$systemInfo->currentTimeMillis();
?>
What should I do?

1) Should I copy my class to the standard location where all Java classes are kept. (What is this location?)

2) Do some changes in the php.ini file
katierosy
Forum Commoner
Posts: 27
Joined: Wed Apr 07, 2010 8:39 am

Re: Problem calling Java from PHP script

Post by katierosy »

You should keep it in a place where all other php scripts works. May be you will think to read more on using java in PHP.
Post Reply