Home > Backend Development > PHP Tutorial > Java extensions in PHP_PHP Tutorial

Java extensions in PHP_PHP Tutorial

WBOY
Release: 2016-07-13 17:21:18
Original
858 people have browsed it

The extensibility of Java is one of its extremely exciting uses. By learning how to use this module, you can extend all available Java classes. To give you an understanding of the basics of Java extensibility, this article includes system installation and some code examples for using PHP and Java together.

Installation under Windows

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

Step one: Install JDK
This process is thought to be simple, since there are not too many problems with the installation of JDK, but what you need to do is check your system environment (autoexec.bat and NT environment in Windows9X Go to "System" in the "Control Panel") and confirm whether the JDK1.x.x in path is loaded into the path. This setting will make it easier for you to compile Java classes. Join in Win9x

PATH=%PATH%;C:jdk1.2.2 in

Go to your system’s autoexec.bat and add it to the NT system

;C:jdk1.2.2 in

to the end of the Path environment variable. The annotation of autoexec.bat in the system is very important. PHP's Java extension will ignore the installation paths of JAVA_HOME and CLASSPATH in the system. Therefore, it is very important to correctly set these items in php.ini.

Step 2: Modify 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.2jre inCLASSICjvm.dll
java.library. path=c:webphp4extensions
java.class.path="c:webphp4extensionsjdk1.2.2php_java.jar;c:myclasses"

A typical problem is that some people put extension=php_java.dll together with other extensions in the php.ini file, but its correct location should be [java] in the php.ini file. under. java.library.path must be set in php_java.dll, and java.class.path must contain the path to php_java.jar. java.class.path also needs to add other paths where you may use other classes, such as c:myclasses in the example above, or you can just write the previous path.

Step 3: Test your installation
Now, you can create a php program similar to this:

$system = new Java("java.lang.System");
print "Java version=".$system->getProperty("java.version")."
";
print "Java vendor=".$system->getProperty("java.vendor")."

";
print "OS=".$system->getProperty("os.name")." ".
$system->getProperty("os.version")." on ".
$system->getProperty("os.arch")."
";

$formatter = new Java("java.text.SimpleDateFormat","EEEE,
MMMM dd, yyyy at h:mm:ss a zzzz");
print $formatter->format(new Java("java.util.Date"))." ";

?>
This is an example made by Sam Ruby. If you set everything, you will see results like this:
Java version= 1.2.2
Java vendor=Sun Microsystems Inc.
OS=Windows 95 4.10 on x86
Wednesday, October 18, 2000 at 10:22:45 AM China Standard Time

(Translator's Note: The result of running on my machine:
Java version=1.2.2
Java vendor=Sun Microsystems Inc.
OS=Windows 95 4.90 on x86
Wednesday , March 28, 2001 at 1:44:33 pm GMT+08:00 )

This is a very simple example, but it can tell you how to access java classes using php. Once you can get this example running, it means that your php java extension has been installed successfully.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532489.htmlTechArticleJava’s easy extensibility is one of its extremely exciting uses. By learning how to use this module, You can extend all available Java classes. To give you an idea of ​​Java extensibility...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template