How does PHP call Java class library

xiaoxiao2021-03-06  65

How PHP class library to call JAVA Author: Wandering | View: 244 | Comments: 0

Java is a very powerful programming tool, its expansion library is also very useful, this tutorial, mainly telling how to use the PHP call function powerful Java class library (Classes). In order to facilitate your study, this tutorial will include Java installation and some basic examples. The first step under Windows: Install JDK, which is very easy, you only need to install it through the way. Then do the following steps. Under Win9X: "Path =% Path%; C: /JDK1.2.2/bin" to the autoexec.bat file. Add "; c: /jdk1.2.2/bin" to the environment variable. This step is very important so that PHP can find the Java class that needs to be called correctly. Step 2: Modify your php.ini file. [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 "java.home =" d: /jdk1.2.2/j "java.library =" d: /jdk1.2.2/jre/bin/server/jvm.dll "Note: PHP5 has no stable Java extension, so follows Configuration will cause Apache crash - deep. Add Extension = php_java.dll in php.ini, and set up java.class.path in [Java], let it point to php_java.jar, if you use new Java classes, you should also deposit this path In this example, we use the catalog of c: / myclasses.

Step 3: Test the environment, create the following PHP file: 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";?> If you are properly installed, you will see the following information: 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, we have successfully established a PHP running environment that can use Java classes, we can start our next course. Example 1: Creating and using your own Java class to create your own Java class is very easy.

Create a phptest.java file, place it in your java.class.path directory, the file content is as follows: public class phptest {/ ** * a sample of a class this can work with php * NB: The Whole Class Must be public to work, * and of course the methods you wish to call * directly * * Also note that from PHP the main method * will not be called * / public String foo;. / ** * Takes a string and returns the result * OR A MSG SAYING YOUR STRING WAS EMPTY * / PUBLIC STRING TEST (STRING STR) {IF (Str.Equals (")) {str.e" your string was empty. ";} return str;} / ** * whatisfoo () simply returns the value of the variable foo. * / public string whatisfoo () {Return "foo is" foo;} / ** * this is called if phptest is run from the commit line with * something like * java phptest * or * java phptest hello there * / public static void main (string args []) {phptest p = new phptest (); IF (args.length == 0) {string arg = ""; system.out.println (p.test (arg));} else {for (int i = 0; i

转载请注明原文地址:https://www.9cbs.com/read-89974.html

New Post(0)