PHP-Java-Bridge usage note _ php instance

Source: Internet
Author: User
This is the notes for calling interfaces using PHP-Java-Bridge when I am working on the development of Ping An Bank and using the PHP environment. Because the tutorials on the Internet are basically useless, I can post the latest online version () here. if there is a problem, please contact us by email. thank you. /** =================================================== ======================================

* @ Author ken (695093513@qq.com)

* @ Date 2014-09-09

*
========================================================== ======================================= **/

/** =================================================== ======================================

* Version and environment

*
========================================================== ======================================= **/

Version:

1. PHP version: the maximum value is 5.4. The current test is 5.4/5.3.

2. JDK: The latest official version. The current test is 1.8.

3. php-java-bridge: The latest official version. The current test is 6.2.1.

4. Operating system: Windows 7 32-bit/64-bit | Linux (Centos6.5)

/** =================================================== ======================================

* Installation and use

*
========================================================== ======================================= **/

Step 1: Install

1. JDK installation: install JDK normally and configure environment variables.

2. PHP installation: normal installation

3. install php-java-bridge:

① Download the Java server Tomcat for normal installation. after installation, enable the Tomcat server

② Place the downloaded php-java-bridge package under webapps

③ Wait for Tomcat to execute parsing and a folder with the same name will be generated under this directory

④ Copy the folder to the Apache server and use

(Note: online tutorials can be used normally. you can call java system functions and simple jar packages. however, complicated jar packages may encounter various problems, so we recommend using this method)

Step 2: Use

1. you do not need to enable Tomcat (it is best to disable it), enable apache server, and double-click to run javabridge. jar, select port 8080 (javabridge. jar also needs to be placed under the Java virtual machine, see the second rule below ).

2. try to put the jar package under the Java virtual machine, that is, the jre installation (for example, C: \ Program Files \ Java \ jre1.8.0 _ 20 \ lib \ ext)

3. you do not need to reference the jar package in the PHP file, because it is placed under the virtual machine, java will automatically call

(Note: javabridge. jar in is obtained in Step 1: installation)

/** =================================================== ======================================

* Other usage and precautions

*
========================================================== ======================================= **/

Various functions of PHP-Java-Bridge:

1. the later version of java_require is no longer used and cannot be used. because it is placed under the Java virtual machine, you do not need to manually introduce the package file.

2. java_value () is used to obtain the value and must be used to obtain the value.

(Note: If the value needs to be stored in the database, you must use the java_value function. Otherwise, an error is reported or the value cannot be stored in the database)

3. java_inspect () performs print_r-like output on instantiation or methods

(Note: do not directly use output methods such as var_dump to output java classes, methods, and variables. you must use java_inspect or java_value, for example, var_dump (java_inspect ($ abc )))

4. The $ test = new Java ("Test") method is used for instantiation. if a parameter exists in the instantiated method, new Java ("Test", "pram") can be used in this way ")

Note:

1. make sure that the references to java. inc are correct.

2. ensure that the jar package can be referenced, for example, under the Java virtual machine jre.

3. call Java in PHP to use PHP.

/** =================================================== ======================================

* Appendix 1: troubleshooting of various errors

* Appendix 2: PHP instance code

* Appendix 3: Directory chart after extracting the PHP-Java-bridge package

*

========================================================== ======================================= **/

Appendix 1: troubleshooting of various errors

1. refer to the above "other usage methods and precautions". most of the problems are path references. if the problem is handled properly and obtained correctly, no problems will occur.

Appendix 2: PHP instance code

require_once("/java/Java.inc");$util = new Java("com.sdb.payclient.core.PayclientInterfaceUtil");$input = new Java("com.ecc.emp.data.KeyedCollection");$signDataput = new Java("com.ecc.emp.data.KeyedCollection");$input->put("masterId","111111");$input->put("orderId","222222");$signDataput = $util->getSignData($input);$orig = java_values($signDataput->getDataValue("orig"));$sign = $signDataput->getDataValue("sign");echo java_values($sign);

Appendix 3: Directory chart after extracting the PHP-Java-bridge package

bridge --java java.inc JavaProxy.php --WEB-INF --cgi --... --lib php-script.jar php-servlet.jar --pear web.xml weblogic.xml

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.