Connect PHP and Java -- PHP/JavaBridge [3]

Source: Internet
Author: User
Connect PHP and Java -- PHPJavaBridge [3] Haohappy
PHP5 Research Center: http://blog.csdn.net/haohappy2004/

Install PHP/Java Bridge

If you are using a RedHat Linux system (RedHat Enterprise or Fedora), you can download a 32-bit RPM package from the home page and enter the rpm-I php-java-bridge-v.x.y-z-i386.rpm to install it. If you are using a 64-bit system and a 64-bit virtual machine, you need to install a 64-bit RPM package. For other systems, see the following introduction.

(1) before installing PHP/Java Bridge, make sure you have installed:
Java1.4 or later,
Gcc3.2 or later,
Apache1.3 or later,
Autoconf2.57 or later, Done
Libtool 1.4.3 or later, Done
Automake1.6.3 or later,
GNU make Done
Php4.3.2 or later

You can run the java-version, gcc -- version, apachectl-version, libtool -- version, automake -- version, make null -- version, autoconf -- version and php-config commands? To determine the version of these packages.

(2) Download the source code of PHP/Java Bridge
Http://www.sourceforge.net/projects/php-java-bridge

(3)
Decompress: cat php-java-bridge_v.x.y.tar.bz2 | bunzip2 | tar xf?

(4)

Run the following command in the extracted directory php-java-bridge-v.x.y:

Phpize &./configure -- disable-servlet -- with-java =/opt/IBMJava2-14 & make CFLAGS = "-m32"

Generate a module for a 32-bit JVM.

(5) install the generated module
Su-c 'make install'

(6) PHP/Java Bridge can be run as sub-component of the WEB server. add the following line to php. ini, or write this line to a file java. ini. copy ini to the directory that contains the description of the php module, such as/etc/php. d /.

Extension = java. so
[Java]

(7) restart the apache Server:/www/apache/bin/apachectl restart

(8) now you can test web installation. Copy test. php to the root directory of the site (for example,/var/www/html) and access it through a browser. You can see that the bridge module is activated and running. Bridge will start as the server starts.

Test. php

Phpinfo ();

Print "\ n ";

$ V = new java ("java. lang. System ");

$ Arr = $ v-> getProperties ();

Foreach ($ arr as $ key => $ value ){

Print $ key. "->". $ value ."
\ N ";

}

?>

Installation on Windows:

1. decompress php-java-bridge_2.0.4-win32-php5.zip and copy all files to C: \ php.

2. double-click c: \ php5 \ JavaBridge. jar or execute java-jar JavaBridge. jar in the command line.

3. php-cgi test. php> result.html (test. php source code can be found in the previous example)

4. open result.html with a browser to view the running result.

The test program first outputs all the options of the php environment, and then creates a Java object and returns its related information.

Running result:

Java. runtime. name-> Java (TM) 2 Runtime Environment, Standard Edition
Sun. boot. library. path-> C: \ Program Files \ Java \ j2re1.4.2 _ 05 \ bin
Java. vm. version-> 1.4.2 _ 05-b04
Java. vm. vendor-> Sun Microsystems Inc.
Java. vendor. url-> http://java.sun.com/
Path. separator->;
Java. vm. name-> Java HotSpot (TM) Client VM
File. encoding. pkg-> sun. io
User. country-> CN
Sun. OS. patch. level-> Service Pack 2
Java. vm. specification. name-> Java Virtual Machine Specification
User. dir-> C: \ php
Java. runtime. version-> 1.4.2 _ 05-b04
Java. awt. graphicsenv-> sun. awt. Win32GraphicsEnvironment
Java. endorsed. dirs-> C: \ Program Files \ Java \ j2re1.4.2 _ 05 \ lib \ endorsed
OS. arch-> x86
Java. io. tmpdir-> C: \ release e ~ 1 \ 506C \ LOCALS ~ 1 \ Temp \
Line. separator->
Java. vm. specification. vendor-> Sun Microsystems Inc.
User. variant->
OS. name-> Windows XP
Sun. java2d. fontpath->
Java. library. path-> C: \ Program Files \ Java \ j2re1.4.2 _ 05 \ bin ;.; c: \ WINDOWS \ system32; C: \ WINDOWS; C: \ j2sdk1.4.2 _ 05 \ bin ;.; c: \ j2sdk1.4.2 _ 05 \ lib; C: \ j2sdk1.4.2 _ 05 \ jre \ lib; C: \ Program Files \ SecureCRT 3.0; C: \ WINDOWS \ system32; C: \ Program Files \ ChemOffice2002 \ Common \ DLLs
Java. specification. name-> Java Platform API Specification
Java. class. version-> 48.0
Java. util. prefs. PreferencesFactory-> java. util. prefs. WindowsPreferencesFactory
OS. version-> 5.1
User. home-> C: \ Documents Ents and Settings \ 506C
User. timezone->
Java. awt. printerjob-> sun. awt. windows. WPrinterJob
File. encoding-> GBK
Java. specification. version--> 1.4
Java. class. path-> C: \ php \ JavaBridge. jar
User. name-> 506C
Java. vm. specification. version-> 1.0
Java. home-> C: \ Program Files \ Java \ j2re1.4.2 _ 05
Sun. arch. data. model-> 32
User. language-> zh
Java. specification. vendor-> Sun Microsystems Inc.
Awt. toolkit-> sun. awt. windows. WToolkit
Java.vm.info-> mixed mode
Java. version-> 1.4.2 _ 05
Java. ext. dirs-> C: \ Program Files \ Java \ j2re1.4.2 _ 05 \ lib \ ext
Sun. boot. class. path-> C: \ Program Files \ Java \ j2re1.4.2 _ 05 \ lib \ rt. jar; C: \ Program Files \ Java \ j2re1.4.2 _ 05 \ lib \ i18n. jar; C: \ Program Files \ Java \ j2re1.4.2 _ 05 \ lib \ sunrsasign. jar; C: \ Program Files \ Java \ j2re1.4.2 _ 05 \ lib \ jsse. jar; C: \ Program Files \ Java \ j2re1.4.2 _ 05 \ lib \ jce. jar; C: \ Program Files \ Java \ j2re1.4.2 _ 05 \ lib \ charsets. jar; C: \ Program Files \ Java \ j2re1.4.2 _ 05 \ classes
Java. vendor-> Sun Microsystems Inc.
File. separator-> \
Java. vendor. url. bug-> http://java.sun.com/cgi-bin/bugreport.cgi
Sun. io. unicode. encoding-> UnicodeLittle
Sun. cpu. endian-> little
Sun. cpu. isalist-> pentium istmi386

Here, we can freely communicate with Java objects and implement the bridge between PHP and Java.

5. modify your php. ini (C: \ Windows \ php. ini) and remove the semicolon before extension = php_java.dll.

Note that php also comes with a php_java.dll located in C: \ php \ extensions, which is different from that provided by php-java-bridge. To avoid errors, set extension_dir in php. ini. by default, extension_dir = "./" points to the C: \ php directory.



References:

[1] JSR 223: Scripting for the JavaTM Platform

[2] PHP/Java Bridge @ sourceforge.net



Trackback: http://tb.blog.csdn.net/TrackBack.aspx? PostId = 627896

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.