Latest PHP Java Bridge usage and Problems

Source: Internet
Author: User

Latest PHP Java Bridge usage and Problems

 

Calling Java components in PHP makes it difficult for me to learn PHP from the very beginning. A search in Google introducesArticleThere are still many. In general, there are two ways to solve this problem: 1. Use php_java.dll extension; 2. Use PHP Java Bridge.

The first method is to modify PHP. INI: it seems that everything went well to restart Apache. But as long as the page is executed to the place where Java is called, Apache will pop up the error in memory that cannot be read. I found other information and said to put PHP. the memory_limi setting in INI is larger, but the same problem still occurs until it is set to MB. No, so we have to adopt the second method.

To sf.netdownload php-java-bridge_4.0.3_j2ee.zip, but the problem again, online information is 3.0 version, and said there is a java-x86-windows.dll, but now the 4.0 package does not, the most terrible or E text is too bad, I can't understand the instruction documents in it. What should I do? I can only touch the stones and cross the river. Every configuration method is tried and cannot run normally. I still can only read the instruction documents with a hard head.

Originally, it had to put javabridge first. war unzipping, there is a javabridge in javabridge \ WEB-INF \ Lib. JAR file. Use the command line to call Java-jar javabridge. jar or double-click javabridge. jar, select the listening port in the pop-up window. (It should be noted that it is best to use port 80 when installing Apache, while javabridge allows it to use port 8080, which saves the trouble of configuring it, if your Apache uses port 8080, javabridge can only use other ports and Java/options. the javabridge port needs to be modified in Inc .)

Copy the entire Java folder in javabridge to the PHP Directory, and add the followingCode:

Require_once ("Java/Java. Inc ");

Try {

$ System = new Java ('java. Lang. system ');

// Demonstrate property access

Echo 'java version = '. $ system-> getproperty ('java. version').' <br/> ';

Echo 'java vendor = '. $ system-> getproperty ('java. upload').' <br/> ';

Echo 'OS ='. $ system-> getproperty ('OS. name ').''.

$ System-> getproperty ('OS. version'). 'On '.

$ System-> getproperty ('OS. Arch'). '<br/> ';

}

Catch (javaexception $ E)

{

Echo $ e-> getcause ();

}
, Ie to refresh the page, you can see the following running results:

Java version = 1.6.0
Java vendor = Sun Microsystems Inc.
OS = Windows XP 5.1 on x86.

In this case, the operation is normal, but I need to call my own components and add a line of code,

Require_once ("Java/Java. Inc ");

 

$ System = new Java ('java. Lang. system ');

 

Java_require ("C: \ appserv \ www \ test \ eucpcommhttp. Jar ");

Try {

$ System = new Java ('java. Lang. system ');

// Demonstrate property access

Echo 'java version = '. $ system-> getproperty ('java. version').' <br/> ';

Echo 'java vendor = '. $ system-> getproperty ('java. upload').' <br/> ';

Echo 'OS ='. $ system-> getproperty ('OS. name ').''.

$ System-> getproperty ('OS. version'). 'On '.

$ System-> getproperty ('OS. Arch'). '<br/> ';

}

Catch (javaexception $ E)

{

Echo $ e-> getcause ();

}

When the page is refreshed:

[[O: illegalstateexception]: "Java. lang. illegalstateexception: java_require () not allowed for the HTTP tunnel. use a context runner instead. "At: #-7 PHP. java. bridge. javabridgeclassloader. checkcl (javabridgeclassloader. java: 55) #-6 PHP. java. bridge. simplejavabridgeclassloader. forname (simplejavabridgeclassloader. java: 187) #-5 PHP. java. bridge. javabridge. createobject (javabridge. java: 514) #0 C: \ appserv \ www \ test \ javabridge \ Java. INC (151): java_exceptionproxyfactory-> getproxy (2, true) #1 c: \ appserv \ www \ test \ javabridge \ Java. INC (304): java_arg-> getresult (true) #2 c: \ appserv \ www \ test \ javabridge \ Java. INC (310): java_client-> getwrappedresult (true) #3 c: \ appserv \ www \ test \ javabridge \ Java. INC (489): java_client-> getresult () #4 c: \ appserv \ www \ test \ javabridge \ Java. INC (735): java_client-> invokemethod (1, 'getcause', array) #5 c: \ appserv \ www \ test \ javabridge \ Java. INC (956): java_javaproxy->__ call ('getcause', array) #6 [internal function]: java_exception->__ call ('getcause', array) #7 C: \ appserv \ www \ test \ smstest. PHP (39): java_internalexception-> getcause () #8 {main}]

If you refresh the page again, the problem occurs again.

So far, there has been no progress. This may have been a bug in PHP Java Bridge, and I have to discuss other solutions with the customer.

I also hope that some people who know the reason can give me some tips!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.