Connecting PHP and Java-Php/java Bridge [3]

Source: Internet
Author: User
Tags what php
Haohappy
PHP5 Research Center: HTTP://BLOG.CSDN.NET/HAOHAPPY2004/

Installing Php/java Bridge

If you are using the RedHat Linux system (RedHat Enterprise or Fedora), you can download the 32-bit RPM package from the home page and enter 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. Other systems look at the introduction below.

(1) Before installing Php/java Bridge, you need to make sure that 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 use the command java-version, gcc--version, apachectl-version, Libtool--version, automake--version, make null--version, AutoCo NF--version and Php-config. Version to determine the versions of these packages.

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

(3)
Decompression: Cat php-java-bridge_v.x.y.tar.bz2 | BUNZIP2 | Tar XF?

(4)

Execute the command in the unzipped directory php-java-bridge-v.x.y:

Phpize &&/configure--disable-servlet--with-java=/opt/ibmjava2-14 && make cflags= "-m32"

Generates a module for a 32-bit JVM.

(5) Install the generated module
Su-c ' Make install '

(6) Php/java Bridge can be run as the sub-component of the Web server, Add the following line to the php.ini, or write the line to a file Java.ini, and then copy the Java.ini to the directory containing the description of the PHP module, such as/etc/php.d/.

Extension = java.so
[Java]

(7) Restart Apache server:/www/apache/bin/apachectl restart

(8) You are now ready to test your Web installation. Copy the test.php to the site root directory (such as/var/www/html), accessed through the browser. You can see that the bridge module is active 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 under the Windows platform:

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

2. Double-click C:\php5\JavaBridge.jar or execute java-jar at the command line Javabridge.jar

3. php-cgi test.php >result.html (test.php source see above example)

4. Open result.html with your browser to see the results of the run

The segment tester first outputs all the options for the PHP environment, and then creates a new Java object and returns information about it.

Operation 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 HotSpot (TM) Client VM Java.vm.name
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:\docume~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 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
506C, User.Name
Java.vm.specification.version-1.0
Java.home, C:\Program files\java\j2re1.4.2_05
Sun.arch.data.model-32
User.language-en
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 i486 i386

Here, we are free to communicate with the Java object and implement the bridging between PHP and Java.

5. Next Modify your PHP.ini (C:\Windows\php.ini), put the semicolon before the Extension=php_java.dll;

Note that PHP also comes with a php_java.dll, which is located under C:\php\extensions, and is different from what Php-java-bridge offers. To avoid errors, be careful to set the Extension_dir in PHP.ini, the default Extension_dir = "./" to the C:\php directory.



Resources:

[1] JSR 223:scripting for the JAVATM Platform

[2] Php/java Bridge @ sourceforge.net



trackback:http://tb.blog.csdn.net/trackback.aspx?postid=627896

  • 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.