Php-java-bridge Use Notes _php instances

Source: Internet
Author: User
Tags tomcat tomcat server

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

* @author Ken (695093513@qq.com)

* @date 2014-09-09

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

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

* Version and Environment

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

Version:

1, PHP Version: The highest is 5.4, the current test for 5.4/5.3

2, JDK: The latest official version, the current test for 1.8

3, Php-java-bridge: The latest official version, the current test for 6.2.1

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

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

* Installation and use

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

First step: Install

1, the installation of JDK: Normal installation can be, and configure a good 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 Tomcat server

② the downloaded Php-java-bridge package under WebApps

③ waits for Tomcat to perform parsing, the folder with the same name is generated under the directory

④ Copy the folder to the Apache server using the

(Note: Tutorials on the web can work properly, invoke Java system functions and simple jar packages, but it is recommended for complex jar packages to have a variety of problems.)

Step Two: Use

1, do not need to open tomcat (preferably close off), open the 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, as far as possible, put the jar package under the Java virtual machine, that is, under the JRE installation (such as: 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 put under the virtual machine, Java will automatically call

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

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

* Other methods of use and precautions

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

A variety of functions about Php-java-bridge are used:

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

2, Java_value () is used to get the value, and must use the function to get the value

(Special note: If this value needs to be stored in the database, then you must use the Java_value function, or you will not be able to make an error or save the database)

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

(Note: Do not output Java classes, methods, variables directly using the output method such as var_dump, you 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, you can do this new Java ("Test", "pram")

Precautions:

1. Be sure to refer to the java.inc to ensure that the reference is correct

2. Be sure to place the jar pack where it can be referenced, such as the Java Virtual machine JRE below

3, in PHP invoke Java use PHP to the writing can

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

* Appendix 1: Handling All kinds of error problems

* Appendix 2:php Instance Code

* Appendix 3:php-java-bridge file package after decompression catalog map

*

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

Appendix 1: Handling All kinds of error problems

1, referring to the above "other use methods and precautions", most of the problem is the path to refer to the problem, as long as the deal with the right to obtain, 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 Catalog Map after unpacking

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.