note 46706 rejected from ref.java by betz

From: Date: Wed, 27 Oct 2004 13:45:52 +0000
Subject: note 46706 rejected from ref.java by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79175@lists.php.net to get a copy of this message
Note Submitter: hceylan (at) biletix (dot) com ---- 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

« previous php.notes (#79175) next »