PHP & Java(1) (轉)
builder.com/contact.php3?contact=Markn_at_enspace_dot_com">Mark Nold
The 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.
Installation
The following configuration has been tested with .org/">Apache 1.3.12, PHP 4.0.3 binaries from win.de/"> plus the .com/">4.0.3 Zend Optimiser and 1.2.2 from /?frontpage-javaplatform">java.sun.com. We have also tested this configuration with older versions of the JDK and the various MS servers (PWS and IIS) on Windows 95, 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.xbin directory is in your path. This will make compiling your Java Classes easier. On add
PATH=%PATH%;C:jdk1.2.2bin
to your autoexec.bat. On NT add;C:jdk1.2.2bin
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:webphp4extensionsjava.class.path="c:webphp4extensionsjdk1.2.2php_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:
nn"; print "OS=".$system->getProperty("os.name")." ". $system->getProperty("os.version")." on ". $system->getProperty("os.arch")." n"; print "Java vendor=".$system->getProperty("java.vendor")."
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 '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 succesully set up the PHP Java extension.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-987788/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- PHP & Java(4) (轉)PHPJava
- PHP & Java(2) (轉)PHPJava
- PHP & Java(3) (轉)PHPJava
- 應該要PHP轉Java了。。。PHPJava
- 求 PHP 轉 java 的相關教程PHPJava
- PHP 轉 JAVA 篇 小插曲(環境篇)PHPJava
- PHP呼叫java類的兩種方法(轉)PHPJava
- XML的JAVA 解析(一)(1) (轉)XMLJava
- [php]php總結(1)PHP
- 淺談C# vs Java (1) (轉)C#Java
- Java之路( 1 )----幫你完成HelloWorld (轉)Java
- 第1個簡單java程式(轉)Java
- Java Servlet和JSP教程(1)(轉)JavaServletJS
- 在C、JAVA、PHP中操作postgreSql資料庫 (轉)JavaPHPSQL資料庫
- Redhat linux 9下讓PHP支援java類(轉)RedhatLinuxPHPJava
- Java2HTML改造手記(1) (轉)JavaHTML
- Java語言編碼規範(1)(轉)Java
- java截獲標準輸出(1)(轉)Java
- PHP轉Java有沒有好的學習路線PHPJava
- 【PHP基礎】1PHP
- php學習(1)PHP
- php總結_1PHP
- [PHP]XXE 1PHP
- Java程式中的多執行緒(1)(轉)Java執行緒
- PHP and COM (轉)PHP
- Java 2原始碼解讀1:java.util.ArrayList (轉帖收集)Java原始碼
- PHP NG (PHP 5.7) 效能比 PHP 5.6 提升近 1 倍PHP
- PHP中呼叫JAVA,PHPJava
- 1、我的PHP之路PHP
- Java轉iOS:第一個專案總結(1)JavaiOS
- 解析Java的多執行緒機制(1)(轉)Java執行緒
- 轉載:JAVA企業面試題精選 Java基礎 1-10Java面試題
- java時間戳和PHP時間戳的轉換phptime()Java時間戳PHP
- PHP安全配置(轉)PHP
- php.ini (轉)PHP
- PHP:路在何方? (轉)PHP
- PHP 迭代器 (轉)PHP
- PHP安全(2) (轉)PHP