In a previous tutorial it was shown how to set up the php/java bridge on Windows using the Apache
webserever. In this tutorial you learn how to do the same using Windows IIS web server. Though this is a
beginners tutorial you are expected to have some familiarity with IIS. Notice that the version of the PHPJava bridge
used is the older version 3.2.1. Though not the latest version this is the most Windows friendly software. It contains a dll
file that surpasses the one distributed in PHP 5. There is also documentation to be found and you can ask questions about usage on the
mailing list.
Hopefully Zend will take it upon itself to work more closely with Sun and finish the native PHP java bridge. It is a very necessary
tool.
CLASSPATH = .
JAVA_HOME = C:\Program Files\Java\jdk1.5.0_11
PATH = %PATH%;%JAVA_HOME%\bin
To use the ISAPI module, do the following:
Supply .php as the extension. Leave 'Method exclusions' blank, and check the 'Script engine' checkbox. Now, click OK a few times.
...
extension_dir = C:\php\ext
extension = php_java.dll
...
phpinfo();
?>
Note: If your IIS does not load the Java module automatically, most cases, you need to move php.ini (from C:\php) and php_java.dll (from c:\php\ext) to C:\Windows. None of methods listed on the PHP install.txt worked such as setting a path to PHP or editing registry for PHP.
// get instance of Java class java.lang.System in PHP
$system = new Java('java.lang.System');
// demonstrate property access
echo 'Java version=' . $system->getProperty('java.version') . '<br/>';
echo 'Java vendor=' . $system->getProperty('java.vendor') . '<br/>';
echo 'OS=' . $system->getProperty('os.name') . ' ' .
$system->getProperty('os.version') . ' on ' .
$system->getProperty('os.arch') . ' <br/>';
// java.util.Date example
$formatter = new Java('java.text.SimpleDateFormat',
"EEEE, MMMM dd, yyyy 'at' h:mm:ss a zzzz");
echo $formatter->format(new Java('java.util.Date'));
?>
public class HelloWorld {
String hw = "Hello World";
public String getHelloWorld() {
return hw;
}
}
java_require('http://localhost/HelloWorld.jar');
$myObj = new Java('HelloWorld');
// display Hello World
echo (String) $myObj->getHelloWorld();
?>
Originally published by: S.Kang
I have follwed all the steps specified and also i copied the files to c:\windows but the java module does not shown and when i tried to exeute java1.php i got a page can not be displayed page with HTTP 500 internal error. How to execute the java file from php. please tell me.
It sounds as though you have not set up PHP to run on IIS. You’ll have set up PHP to run as a ISAPI module or CGI exe.