note 21892 added to ref.java
| From: | gturner at newedgenetworks dot com | Date: | Thu, 30 May 2002 17:20:16 +0000 |
| Subject: | note 21892 added to ref.java | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-31227@lists.php.net to get a copy of this message | ||
Hello! I have two tips about getting PHP Java to work, hopefully google will pick this up...
After you've followed the instructions (building PHP with Java enabled and hacking php.ini) and
you get a message like:
Fatal error: Cannot instantiate non-existent class: java in (file) on line (line)
That means PHP doesn't know what the 'Java' function is. You can confirm that the
Java extension isn't loaded by looking at 'phpinfo' and verifying that there is no
section titled Java. To fix this you need to edit php.ini and set the 'extensions_dir'
and an 'extension' appropriately. On our system it was 'extension_dir =
/opt/php/lib/php/extensions/no-debug-non-zts-20020429' and an 'extension = java.so'.
All the documentation I found said the extension library should be called 'php_java.so',
but our build produced 'java.so', I have no idea why, YMMV.
The next error message I ran into was:
Fatal error: java.lang.UnsatisfiedLinkError: no php_java in java.library.path in (file) on line
(line)
Yay! this confirms that the JVM is indeed loading (UnsatisfiedLinkError is totally on the Java
side), so relax, you're almost done! What's happening is that the Java class
'net.php.reflect' (a class in php_java.jar that is built by PHP) is trying to execute
'System.loadLibrary("php_java")' and the JVM is unable to find the file named
'libphp_java.so' (or maybe 'php_java.dll' on Windows?). If you ever heard of
LD_LIBRARY_PATH, java.library.path is the same thing. The solution has two parts: First making sure
the php.ini has a 'java.library.path' (in the '[java]' section) that's
pointed at the same directory that 'extension_dir', specifically the directory containing
the file 'java.so' (or maybe 'php_java.so' like everyone else). Second, this
part is bad IMHO, making a symbolic link from the ''java.so' file to
'libphp_java.so' so that Java's System.loadLibrary method can find what it's
looking for (apparently Java prefixes the filename it looks for with "lib"). To make this
symbolic link do 'cd' into the extensions directory and run 'ln -s java.so
libphp_java.so'.
Hope somebody finds this useful!
--
http://www.php.net/manual/en/ref.java.php
http://master.php.net/manage/user-notes.php?action=edit+21892
http://master.php.net/manage/user-notes.php?action=delete+21892
http://master.php.net/manage/user-notes.php?action=reject+21892