Php-java-bridge using Notes

Source: Internet
Author: User
This is when I do ping an bank development, the local use of PHP environment, Ping An interface for the Java interface, the use of Php-java-bridge to invoke the interface notes. Because now the online tutorial basically is not, so posted here I can use and the current online version of the latest (2014-09-19), if wrong, please contact by mail, thank you.

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

* @author Ken (695093513@qq.com)

* @date 2014-09-09

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

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

* Version and Environment

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

Version:

1, PHP Version: Up to 5.4, the current test for 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 for 6.2.1

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

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

* Installation and use

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

First step: Install

1, the installation of the JDK: normal installation can be, and configure the environment variables

2, the installation of PHP: Normal installation can

3, the installation of Php-java-bridge:

① First download Java server Tomcat normal installation, after installation, open the Tomcat server

② put the downloaded Php-java-bridge package under WebApps

③ waits for Tomcat to perform parsing, which will generate a folder of the same name under the directory

④ Copy this folder to the Apache server using the

(Note: Tutorials on the web can be used normally, invoking Java system functions and simple jar packages, but with a variety of problems for complex jar packages, this is recommended)

Step Two: Use

1, do not need to open tomcat (preferably shut down), open Apache Server, double-click Run Javabridge.jar, select 8080 Port (Javabridge.jar also need to be placed under the Java Virtual machine, see the 2nd rule below).

2. Place the jar package below the Java virtual machine as much as possible, i.e. the JRE is installed below (for example: C:\Program files\java\jre1.8.0_20\lib\ext)

3, in the PHP file does not need to refer to the jar package, because placed under the virtual machine, Java will automatically call

(Note: The Javabridge.jar in the 1th is obtained in the first step: 3rd in the installation)

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

* Other use methods and precautions

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

Various functions for Php-java-bridge are used:

1, the high version of the Java_require is no longer used, also can not be used, because placed under the Java Virtual machine, you do not need to manually introduce the package file

2, Java_value () to get the value, and you must use it to get the value

(Special note: If the value needs to be stored in a database, the Java_value function must be used, otherwise it will be an error or cannot be stored in the database)

3, Java_inspect () print_r similar output to the instantiation or method

(Note: Please do not use output methods such as Var_dump to output Java classes, methods, variables, need to use Java_inspect or java_value, for example: Var_dump (Java_inspect ($ABC)))

4. Instantiate using $test = new Java ("test"), if there are parameters in the instantiated method, this can be new Java ("Test", "pram")

Precautions:

1. Be sure to refer to Java.inc to ensure that references are correct

2. Be sure to place the jar package where it can be referenced, such as under the Java Virtual Machine JRE

3, in PHP call Java to use PHP's notation can be

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

* Appendix 1: various Error handling issues

* Appendix 2:php Instance Code

* Appendix 3:php-java-bridge File Package decompression after the directory map

*

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

Appendix 1: Handling of various error problems

1, referring to the above "other use methods and precautions", most of the problem is the path reference problem, as long as the processing is good, correctly obtained, there will be no problem

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:php-java-bridge file Package decompression after directory diagram

Bridge--java java.inc javaproxy.php--web-inf--cgi--...--Lib Php-script.jar php-servlet.jar--pear Web. XML WEBLOGIC.XM L

The above describes the use of Php-java-bridge notes, including aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • Related Article

    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.