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 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 [java] 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 $system = new Java("java.lang.System");
"; $formatter = new Java("java.text.SimpleDateFormat","EEEE, (Translator's Note: The result of running on my machine: 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.
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
You need to add the following items to your php.ini file
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"
Now, you can create a php program similar to this:
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")."
";
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
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 )