/**============================================================
* @author Ken ([email protected])
* @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.xml
Php-java-bridge Use notes, September 2014 latest version