PHP calls java common configuration errors

Source: Internet
Author: User
It has been a long time since I did not develop PHP. recently, to modify an original project, I must support calling Java classes and start to re-operate PHP. I will solve the configuration problem first. Don't talk too much. There are a lot of articles on the Internet, but there are a lot of errors in it. next I will introduce the entire configuration process and share it with you. if you have any questions, please contact us if you are willing to solve them. Note: this article

It has been a long time since I did not develop PHP. recently, to modify an original project, I must support calling Java classes and start to re-operate PHP. I will solve the configuration problem first. Don't talk too much. Online

There are a lot of articles, but there are a lot of errors in it. next I will introduce the whole process of configuration and share it with you. if you have any problems, please contact us if you are willing to solve them.

Note: the normality of this article is only guaranteed for the PHP and JDK versions provided in this article. Other versions are not tested one by one. if you have any questions, please contact us to solve the problem with you.

The installation and configuration of PHP is skipped here (if you have any questions, contact me.Inber_net@hotmail.com)

Test Environment: Windows2003 + IIS + PHP Version 4.3.6 JDK 1.4.1 _ 01

Next, I will first list the incorrect configurations on the Internet as follows:

Error 1
Java. home = D: \ j2sdk14101 \
The error result is as follows:
Can't open D: \ j2sdk14101 \ lib \ tzmappings.
Solution:
Java. home = D: \ j2sdk14101 \ jre

Error 2
Java. class. path = "C: \ PHP \ extensions \ php_java.jar; x: \ Java Class file storage directory \
The error result is as follows:
Fatal error: Call to a member function on a non-object in E: \ inberkong \ public_html \ phproot \ testjava. php on line
Error cause: the user's Java class file is not stored in the x: \ Java Class file storage directory \ or the x: \ Java Class file storage directory \ does not exist
Solution: 1. confirm java. class. path = "C: \ PHP \ extensions \ php_java.jar; x: \ Java Class file directory \ correct
2. check whether the Class file called in PHP is in this directory and make sure it is correct.

The correct configuration is as follows:

Step 1: Make sure the environment is correct
The preceding environment is correctly configured by default.
PHP Directory: C: \ PHP
JDK Directory: D: \ j2sdk14101
Step 2
Find php. ini in C: \ WINDOWS
1. locate extension_dir and configure php_java.jar php_java.dll in the directory.
Extension_dir = "D: \ PHP \ extensions"
2. extension = php_java.dll: remove the semicolon before the configuration information.
Extension = php_java.dll
3. find the configuration items after [java ].
[Java]
Java. class. path = "C: \ PHP \ extensions \ php_java.jar; C: \ PHP \ php_for_class \"
Java. home = D: \ j2sdk14101 \ jre
Java. library = D: \ j2sdk14101 \ jre \ bin \ server \ jvm. dll
Java. library. path = C: \ PHP \ extensions \
Step 3

Write a Java file and compile it in C: \ PHP \ php_for_class \
The Test. java file is as follows:

Package Test;
Public class Test
{
Public String getMessage (String dd)
{
Return "Hello PHP! I am from JAVA. "dd;
}
}

Write a php file testjava. php and call the Test class in the Test package.

$ System = new Java ("java. lang. System ");
Print "Java version =". $ system-> getProperty ("java. version ")."
\ N ";
Print "Java vendor =". $ system-> getProperty ("java. vendor ")."

\ 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 ";

$ B = new Java ("Test. Test ");
$ X = $ B-> getMessage ("
Hello Java! I am from PHP! ");
Echo $ x;

?>
Display result:
Java version = 1.4.1 _ 01
Java vendor = Sun Microsystems Inc.
OS = Windows XP 5.2 on x86
Thursday, March 13, 2006 at 3:00:51 pm China Standard Time

Hello PHP! I am from JAVA.
Hello Java! I am from PHP!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.