Java Extensions in PHP

Source: Internet
Author: User

Java extensibility is one of its most exciting uses, and by learning how to use this module, you can extend all of the Java classes that are available. To give you an idea of the basics of Java extensibility, this article includes the installation of the system and some code examples used in conjunction with PHP and Java.

Install under Windows

The following configuration is based on Apache 1.3.12, PHP 4.0.3 (you can download in www.php4win.de) and JDK1.2.2 (you can download in java.sun.com). We have tried this installation configuration in the older versions of JDK and Windows, the various Ms Webservers (PWS and IIS) under Windows NT4 and.

First step: Install JDK
This process wants to be simple, because the JDK installation is not too much problem, but what you need to do is to look at your system environment (in the Windows9x Autoexec.bat and NT environment in the "Control Panel" in the "system") and confirm jdk1.x.x\ Whether the bin path is loaded into path. This setting will make it easier for you to compile Java classes. Join in the Win9x

path=%path%; C:\jdk1.2.2\bin

To the Autoexec.bat of your system, adding to the NT system.

; C:\jdk1.2.2\bin

To the end of the PATH environment variable. The tagging of Autoexec.bat in the system is very important. PHP's Java extensions will java_home and classpath the installation path in the system, so it is important to set up these projects correctly in php.ini.

Step two: Revise your php.ini.
You need to add the following items to your php.ini file

[Java]
Extension=php_java.dll
Java.home = C:\jdk1.2.2
Java.library = C:\jdk1.2.2\jre\bin\CLASSIC\jvm.dll
Java.library.path=c:\web\php4\extensions\
Java.class.path= "C:\web\php4\extensions\jdk1.2.2\php_java.jar;c:\myclasses"

The representative problem is that some people put extension=php_java.dll with other extensions in php.ini files, but the correct location is in the php.ini file under [Java]. Java.library.path must be set in Php_java.dll, and Java.class.path must include Php_java.jar path. Java.class.path also add other paths that you might use other classes, as shown in the example above c:\myclasses, or you can just write the previous section of the path.

Step three: Test your installation results
Now you can build a PHP program like this:
<?php

$system = new Java ("Java.lang.System");
Print "Java version=". $system->getproperty ("Java.version"). "<br>\n";
Print "Java vendor=". $system->getproperty ("Java.vendor"). "<p>\n\n";
Print "os=". $system->getproperty ("Os.name"). " ".
$system->getproperty ("Os.version"). "On".
$system->getproperty ("Os.arch"). "<br>\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 ";

?>
This is an example of Sam Ruby doing. If you set none, you will see a result like this:
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

(Translator Note: The result of running on my machine:
Java version=1.2.2
Java Vendor=sun Microsystems Inc.
Os=windows 4.90 on x86
Wednesday, March, 2001 at 1:44:33 afternoon gmt+08:00)

This is a very simple example, but it can tell you how to use PHP to access Java classes, and once you have this example turned on, your PHP Java extensions have been installed successfully.



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.