PHP calls java class

Source: Internet
Author: User
PHP calls java class to: http://hi.baidu.com/lei0827/blog/item/28439a4e923234ced1c86a18.html

PHP calls java class in two ways

1. I did not use the php module to call java (but it was proved by netizens that this method was not good.

2. use the php-java-bridge module to call java. (Recommended on the Internet) I used this method.

It took me two days to download the m package because of the broken submarine cable ). Yesterday we finally succeeded with continuous efforts.

The following describes how to install this package in linux.

1. first install the java environment, apache, php and other related environments (installation method is omitted ).

2. download the php-java-bridgepackage (currently I use php-java-bridge-4.0.1.tar.gz)

Tar xzvf php-java-bridge-4.0.1.tar.gz decompression

Cd php-java-bridge-4.0.1 (go to package directory)

Phpize

. /Configure -- disable-servlet -- with-java =/usr/java/jdk1.5.0 _ 06 /, /usr/java/jdk1.5.0 _ 06/jre -- with-php-config =/var/eyou/php/bin/php-config

Make; make install

After the installation is successful, the installation is successful.

Start configuring php. ini

Vi/var/eyou/php/lib/php. ini

To the end of the file

# Java Module
Extension = "java. so"
[Java]

Java. java_home = "/usr/java/jdk1.5.0 _ 06/" (your java installation directory)
Java. java = "/usr/java/jdk1.5.0 _ 06/jre/bin/java" (this will definitely happen in your java installation directory)
Java. log_file = "/var/log/php-java-bridge.log" (location of the log file)
Java. classpath = "/var/eyou/php/lib/php/extensions/no-debug-non-zts-20020429/JavaBridge. jar" (location of JavaBridge. jar)
Java. libpath = "/var/eyou/php/lib/php/extensions/no-debug-non-zts-20020429/" (where custom java classes are stored)
Java. log_level = "2" (log level)

Write the above save and exit.

Restart apache

Phpinfo ();

?>

See if you can find java. If yes, the installation is successful.

Test to see if it can be used.

Vi java. php

// Java_require ("./php_test.jar ");
$ System = new Java ("java. lang. System ");
Print "Java version =". $ system-> getProperty ("java. version ")."";
$ Str = new Java ("java. lang. String ");
$ Str = "abc ";
/* The following is custom. we will introduce it later. Thanks to weipeng for the successful running of the following program
$ UserBook = new Java ("php_test ");
$ UserBook-> test1 = "abc ";
$ UserBook-> test ();
Var_dump ($ userBook-> test1 );

*/
?>

Run the above code and you can see that java is successfully called.

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.