Invoke Java in PHP

Source: Internet
Author: User
Tags ini php file php and version
PHP and Java

Java is a very powerful programming tool, its extension library is also very useful, this tutorial, mainly on how to use PHP invoke powerful Java class library (classes). To facilitate your study, this tutorial will include Java installation and some basic examples.

Installation under Windows

Step One: Install the JDK, it's very easy, you just have to install it all the way to the carriage. Then do the following steps.

Add under Win9x: "path=%path%; C:\jdk1.2.2\bin "to the Autoexec.bat file

To join under nt/win2000 "; C:\jdk1.2.2\bin "to the environment variable.

This step is very important so that PHP can correctly find the Java class that needs to be invoked.

Step Two: Modify your php.ini file.

[Java]

Extension=php_java.dll

Java.library.path=c:\web\php4\extensions\

Java.class.path= "C:\web\php4\extensions\jdk1.2.2\php_java.jar;c:\myclasses"


Add Extension=php_java.dll to PHP.ini

And in [Java], set the Java.class.path to point to Php_java.jar, and if you use the new Java class, you should also deposit this path, and in this example we use the C:\myclasses directory.

Step three: Test the environment, create the following PHP file:

?

$system = new Java ("Java.lang.System");

Print "Java version=". $system->getproperty ("Java.version"). " \ n ";

Print "Java vendor=". $system->getproperty ("Java.vendor"). " \ n ';

Print "os=". $system->getproperty ("Os.name"). " ".

$system->getproperty ("Os.version"). "On".

$system->getproperty ("Os.arch"). " \ n ";

$formatter = new Java ("Java.text.SimpleDateFormat", "Eeee,"

MMMM dd, yyyy ' at ' h:mm:ss a zzzz ');

Print $formatter->format (new Java ("Java.util.Date")). " \ n ";

?>


If you install it correctly, you will see the following information:

Java version=1.2.2

Java Vendor=sun Microsystems Inc.

Os=windows 4.10 on x86

Wednesday, October at 10:22:45 AM-Standard time

In this way, we have successfully built a PHP runtime environment that can use Java classes, and we can start the course we're going to take.



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.