网管联盟 | 网管论坛 | 网管u家 | 网管博客 | 网管软件 | 网管求职 | 小游戏 | 网管搜索 | 网管原创 | 网管聚合 | 网管读摘 | 网管焦点 | 世界素材 | 会员投稿 | 会员中心 
中国网管联盟
Windows Linux Cisco 网络技术 数据库 黑客攻防 DotNet Java PHP 认证 新闻资讯 服务器 存储资讯 网络设备 网管学堂 技术专题 焦点 网吧频道
 当前位置: > bitsCN.com > PHP > PHP技术进阶 > PHP&Java  

PHP&Java

2006-02-27  作者:bitsCN整理  来源:中国网管联盟  点评 投稿 收藏

Mark Nold
Joost Soeterbroek

 

网管u家u.bitsCN.com

The Java extension is an extremely exciting tool. By learning how to use this module, you can extend PHP by the power of all available Java classes. To show you the basics of the Java extension, this article will cover installation and a few code examples of using PHP and Java together. 网管u家u.bitsCN.com

Windows Installation

The following configuration has been tested with Apache 1.3.12, PHP 4.0.3 binaries from www.php4win.de plus the 4.0.3 Zend Optimiser and JDK 1.2.2 from java.sun.com. We have also tested this configuration with older versions of the JDK and the various MS webservers (PWS and IIS) on Windows 95, Windows 98 and NT4.

网管网www_bitscn_com

Step 1: Install the JDK. This is fairly simple, as the JDK installs without many questions. It might be useful to check your environment (autoexec.bat in Windows 9x and System under Control Panel in NT) and make sure the jdk1.x.x\bin directory is in your path. This will make compiling your Java Classes easier. On Win9x add 网管联盟bitsCN_com

PATH=%PATH%;C:\jdk1.2.2\bin
 
中国网管联盟bitsCN.com
to your autoexec.bat. On NT add
;C:\jdk1.2.2\bin
 
网管下载dl.bitscn.com
to the end of the PATH environment variable. It is also important to note in your autoexec.bat file, the PHP Java extension ignores the JAVA_HOME and CLASSPATH set up in the environment. This is important because these items must be set correctly in your php.ini file for the Java extension to work.

网管u家u.bitscn@com

Step 2: Modifying your php.ini. You need to add something similiar to your php.ini file 网管联盟bitsCN@com

 

网管下载dl.bitscn.com

[java]
extension=php_java.dll
java.library.path=c:\web\php4\extensionsjava.class.path="c:\web\php4\extensions\jdk1.2.2\php_java.jar;c:\myclasses"
 中国网管联盟bitsCN.com 

Typically, people put the extension=php_java.dll directive with the rest of the extensions, but it can sit happily under [java]. The java.library.path must be set in the location of the php_java.dll, and java.class.path must include the location of php_java.jar. The java.class.path should also include the path to other classes you may wish to use (note the double quotes!). In these examples, we will be talking about c:\myclasses. You should also note that the single period is ignored by PHP and Java. As far as we know, you cannot set PHP to look in the current directory for its Java classes. 网管联盟bitsCN@com

Step 3: Testing your Install. Now, you're ready to go. Create a PHP file that looks something like this: 中国网管联盟bitsCN.com

 

网管论坛bbs_bitsCN_com


<?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";
?>
 网管网www.bitscn.com 

NB: This is taken directly from Sam Ruby's examples. If you have correctly installed everything, you should see some results like:

网管bitscn_com

  网管u家u.bitsCN.com

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
 网管联盟bitsCN_com 

A very simple example, but it shows you can access currently available Java classes. Once you have this example working, you have successfully set up the PHP Java extension. 网管网www_bitscn_com


TAGs     the   Java   to   and   you   your   of   PHP   in   is   extension   system-get  
 上一篇:php录入页面中动态从数据库中提取数据的实现   下一篇:Linux网络管理员手册
PHP&Java 评论:
loading.. 评论加载中…
评论:请自觉遵守互联网相关政策法规,评论不得超过250字。

验证码: 注册用户
本类热门排行:
最新推荐文章:
网管论坛交流: