note 46706 added to ref.java
| From: | dot) | Date: | Wed, 20 Oct 2004 19:27:06 +0000 |
| Subject: | note 46706 added to ref.java | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78850@lists.php.net to get a copy of this message | ||
Hi all,
I was looking desparately for a solution to broken java - php integration problem all day long
today.
Digging the internet finally I came accross with a solution provided by Tony J. White
<tjw@tjw.org>. Seeing that the solution has been avail for almost a year, and a large number
of people still trying to overcome the problem, I decided the post the solution to the manual.
Tony made a good explanation to the issue and has found the by solution to it. Interested ones might
want to take a look at his page @ http://tjw.org/php_java ...
Just in case his web site might be unavailable in the future,
I decided to post his solution to here. I am sure Tony would not mind that.
Here's the patch that needs to go in java.c
--- java.c.cvs 2003-11-26 12:43:34.000000000 -0600
+++ java.c 2003-11-26 13:08:46.000000000 -0600
@@ -89,10 +89,11 @@
static void *dl_handle = 0;
+JavaVM *JVM;
+
/* {{{ ZEND_BEGIN_MODULE_GLOBALS
*/
ZEND_BEGIN_MODULE_GLOBALS(java)
- JavaVM *jvm;
JNIEnv *jenv;
jobject php_reflect;
jclass reflect_class;
@@ -169,11 +170,12 @@
*/
static int jvm_create(TSRMLS_D)
{
- int rc;
+ jint rc;
jobject local_php_reflect;
jthrowable error;
jint (JNICALL *JNI_CreateVM)(const void*, const void*, void*);
+
#ifndef JNI_12
jint (JNICALL *JNI_DefaultArgs)(void*);
#endif
@@ -251,11 +253,19 @@
#endif
- rc = (*JNI_CreateVM)(&JG(jvm), &JG(jenv), &vm_args);
-
- if (rc) {
- php_error(E_ERROR, "Unable to create Java Virtual Machine");
- return rc;
+ if (JVM == NULL) {
+ rc = (*JNI_CreateVM)(&JVM, &JG(jenv), &vm_args);
+ if (rc) {
+ php_error(E_ERROR, "Unable to create Java Virtual Machine");
+ return rc;
+ }
+ }
+ else {
+ rc = (*JVM)->AttachCurrentThread(JVM, (void**)&JG(jenv), NULL);
+ if (rc) {
+ php_error(E_ERROR, "Unable to AttachCurrentThread to jenv!");
+ return rc;
+ }
}
JG(reflect_class) = (*JG(jenv))->FindClass(JG(jenv), "net/php/reflect");
@@ -664,7 +674,7 @@
PHP_MSHUTDOWN_FUNCTION(java)
{
UNREGISTER_INI_ENTRIES();
- if (JG(jvm)) jvm_destroy(TSRMLS_C);
+ if (JVM) jvm_destroy(TSRMLS_C);
return SUCCESS;
}
/* }}} */
If you have trouble compiling php in Windoze. Drop me an email. I can send you the binary
php_java.dll file.
Hasan Ceylan
----
Manual Page -- http://www.php.net/manual/en/ref.java.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46706
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46706&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46706&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46706&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46706&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46706&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46706&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46706&report=yes
Search -- http://master.php.net/manage/user-notes.php