Click to See Complete Forum and Search --> : PHP4.0.4cannot find java virtual machine


Anon
02-13-2001, 01:22 AM
I am using IIS on NT configured to use php4.0.4

I configured the [java] section in php.ini with
java.home = c:\jdk1.2
java.class.path = ".;c:\php\extensions\...jar;"

when I run a simple script to display the version using System.getProperty("Java Version"), it returns with a fatal error taht Java Virtual Machine could not be found

akilov
02-13-2001, 10:50 AM
Sandeep,

You need some additional entries in your [java] section such as java.library, java.library.path, extension_dir, extension. Please browse the archives in this forum. For example:

http://www.phpbuilder.com/forum/read.php3?num=3&id=103405&thread=103350

Alex

Anon
02-15-2001, 01:20 AM
Alex,
thanx for your response. java in my php now runs. But my servlet still doesn't work. I am using javawebserver2.0. Any one who knows how to run servlets through php may please tell what all to download and how to configure it for winNT.

For all other php users with similar situation like
mine, I explain the steps I followed on winnt:

Anitha,
I thing U may also be able to run java on php using the following steps.

Pre-setup activity - I un-installed jdk1.2 and installed jdk1.2.2 downloadable from sun.

1. U could use php.exe or php4isapi.dll. It works with both.

2. Uncomment the php_java.dll from the extensions list after setting the path of extensions_dir to say "c:\php\extensions"

Make following changes to the [Java] section

[Java]
java.class.path = ".;c:\php\extensions\php_java.jar"
java.home = c:\jdk1.2.2
java.library = c:\jdk1.2.2\jre\bin\classic\jvm.dll
java.library.path = "c:\php\extensions"

Stop and then Restart your webserver. Place a php file containing java object in your webroot. You may use the following:
<?

$system = new Java("java.lang.System");
print "Java version=".$system->getProperty("java.version")." <br>\n";
print "Java vendor=".$system->getProperty("java.vendor")." <p>\n\n";
print "OS=".$system->getProperty("os.name")." ".
$system->getProperty("os.version")." on ".
$system->getProperty("os.arch")." <br>\n";

$formatter = new Java("java.text.SimpleDateFormat",
"EEEE, MMMM dd, yyyy 'at' h:mm:ss a zzzz");

print $formatter->format(new Java("java.util.Date"))."\n";

?>

execute the above file from your browser and ... say cheers...

akilov
02-15-2001, 10:18 AM
Sandeep,

PHP/Servlet and PHP/Java are very different to set up. With servlet, you should NOT have a [Java] section in PHP.INI. Nor should you have to modify your HTTP server's config file to add php processing. The Sapi you'll be using is phpsrvlt INSTEAD of phpisapi, phpapache, CGI or what not.

To set up PHP/Servlet you should figure out how to add servlets to your java server and define a servlet called "php" which points at the class net.php.servlet. Also, add the phpsrvlt.jar to your java server's CLASSPATH. Next, associate the URI *.php with your newly defined "php" servlet. Last but not least, make sure that the phpsrvlt.dll and php4ts.dll are visible in the PATH.

Unfortunately, the above set up is different for every java web server. The sapi/servlet/README talks about how to set it up with Jakarta's Tomcat. With the latter, it's simply a matter of adding some XML (included with the PHP distribution) to the webapp's web.xml configuration file. I've gotten PHP/Servlet to run in IBM's Websphere, by using the Add Servlet wizard (specifying everything I mentioned in the above paragraph). If you are familiar with your java webserver and know how to add servlets you should have the necessary knowledge of what to do to add the php servlet. Personally, I find it much easier to set up than PHP/Java and the performance of loading JVM's should be much better. Reliability is another issue but that's currently under work.

Unfortunately, with this post, I must bid farewell to this forum. I'm resigning from my post today to pursue a life elsewhere. Best of luck to everybody with PHP and Java and Servlets. Hope my contributions over the last few months were worthwhile. Perhaps someone can add a FAQ entry somewhere that summarizes everything I've been trying to teach you all.

Be seeing you,

Alex