search
Homephp教程php手册PHP中调用JAVA

PHP中调用JAVA

Jun 13, 2016 pm 12:46 PM
javaphpandsharp weaponLibrarypowerfulExpandit worksofprogrammingtransfer


PHP与JAVA

JAVA是个非常强大的编程利器,它的扩展库也是非常的有用,这篇教程,主要讲述怎样使用PHP调用功能强大的JAVA 类库(classes)。为了方便你的学习,这篇教程将包括JAVA的安装及一些基本的例子。

windows下的安装

第一步:安装JDK,这是非常容易的,你只需一路回车的安装好。然后做好以下步骤。

在 Win9x 下加入 :“PATH=%PATH%;C:\jdk1.2.2\bin” 到AUTOEXEC.BAT文件中

在 NT /Win2000下加入 “;C:\jdk1.2.2\bin”到环境变量中。

这一步是非常重要的,这样PHP才能正确的找到需调用的JAVA类。

第二步:修改你的PHP.INI文件。

[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"


在PHP.INI中加入extension=php_java.dll

并在[java]中,设定好java.class.path,让它指向php_java.jar,如果你使用新的JAVA类,你也应该存入这个路径,在这篇例子中,我们使用c:\myclasses这个目录。

第三步:测试环境,创建如下PHP文件:



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

print "Java version=".$system->getProperty("java.version")."\n";

print "Java vendor=".$system->getProperty("java.vendor")."\n\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";

?>


如果你正确安装了,你将会看到以下信息:

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

这样,我们就已经成功的建立起了可以使用JAVA类的PHP运行环境,我们可以开始我们接下去的课程了。

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools