PHP & Java(1)

原创 2001年01月09日 15:27:00

Mark Nold
Joost Soeterbroek

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.

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.

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

PATH=%PATH%;C:/jdk1.2.2/bin
to your autoexec.bat. On NT add
;C:/jdk1.2.2/bin
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.

Step 2: Modifying your php.ini. You need to add something similiar to your php.ini file

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

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.

Step 3: Testing your Install. Now, you're ready to go. Create a PHP file that looks something 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";
  
?>

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

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 

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.

Java对PHP服务器hmac_sha1签名认证方法的匹配实现

如果你的API服务安全认证协议中要求使用hmac_sha1方法对信息进行编码, 而你的服务是由PHP实现的,客户端是由JAVA实现的,那么为了对签名正确比对,就需要在两者之间建立能匹配的编码方式.PH...
  • iefreer
  • iefreer
  • 2012年08月14日 12:28
  • 9182

atitit. web 在线文件管理器最佳实践(1)--- elFinder 的使用流程解决之道 。打开浏览服务器文件夹java .net php

atitit. web 在线文件管理器最佳实践(1)--- elFinder 的使用流程解决之道 。打开浏览服务器文件夹java .net php   1. 环境:::项目java web,需要打...
  • attilax
  • attilax
  • 2014年10月06日 08:02
  • 4617

Paip.Php Java 异步编程。推模型与拉模型。响应式(Reactive)”编程FutureData总结... 1

Paip.Php  Java 异步编程。推模型与拉模型。响应式(Reactive)”编程FutureData总结... 1 1.1.1       异步调用的实现以及角色(:调用者 提货单) F...
  • attilax
  • attilax
  • 2014年01月21日 23:08
  • 2167

Atitit.实现反向代理(1)----url rewrite 配置and内容改写 and -绝对路径链接改写 java php

Atitit.实现反向代理(1)----url rewrite  配置and内容改写 and -绝对路径链接改写 java php   1. 代理的实现:::普通代理and反向代理?? 1 ...
  • attilax
  • attilax
  • 2014年08月25日 20:29
  • 2803

barcodegen.1d-php4.v2.2.0.zip

  • 2017年06月12日 10:46
  • 262KB
  • 下载

PHP CI 框架教程 (1) -- 安装和简介

1. 安装 从 http://www.codeigniter.com/download 下载,有2个可选版本,可根据需要选择。 下载后解压缩,然后放到你应用服务器对应的程序目录中即可,如MAC (/L...

txlgl_v1php有关的知识

  • 2015年02月11日 19:28
  • 3.15MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:PHP & Java(1)
举报原因:
原因补充:

(最多只允许输入30个字)