PHP calls Java class common configuration error

Source: Internet
Author: User
Tags configuration php getmessage php file php and
Error

Do not engage in PHP development work for a long time, recently modified a original project to support the call Java class, start to Redo PHP, the first solution to the configuration problem. Don't say too much crap. On the Internet

Article a lot, but there are many wrong things in the inside, I introduce the following I configure the entire process to share with you, if there is a problem can be contacted if you are willing to solve.

Note: The normal nature of this article is only for the version of PHP and JDK provided in this article, other versions of the test, if there is a problem in a timely manner to work with you to resolve related issues.

Install configuration PHP work here is skipped (there will be no friends can contact me inber_net@hotmail.com)

Test environment: windows2003+iis+php Version 4.3.6+jdk 1.4.1_01

Below I will first list the wrong configuration lists on the web as follows

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

Error configuration 2
Java.class.path = "C:\php\extensions\php_java.jar;x:\java class file save directory \
The error results are as follows:
Fatal Error:call to A's function on a non-object in E:\inberkong\public_html\phproot\testjava.php
Error reason: User Java class file not stored in X:\Java class file directory \ or X:\Java class file save directory \ does not exist
Workaround: 1 Determine java.class.path = "C:\php\extensions\php_java.jar;x:\java class file save directory \ Correct
2 Determine if there is a class file called in PHP in this directory and make sure it is correct

The correct configuration is as follows:

The first step: Determine the environment is correct
The default above environment is configured correctly
PHP Directory: C:\PHP
JDK Catalog: D:\j2sdk14101
Second Step
Find the php.ini under C:\WINDOWS.
1 Find Extension_dir and configure to ensure Php_java.jar Php_java.dll on its directory
Extension_dir = "D:\PHP\extensions"
2 Find; Extension=php_java.dll remove the semicolon before this configuration information
Extension=php_java.dll
3 files find something after [Java] configuration related content
[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\
Third Step

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

Package Test;
public class Test
{
public string GetMessage (string dd)
{
Return "<font Color=green>hello PHP! I am from java.</font> "+DD;
}
}

Write a PHP file testjava.php call the test class in the test package
<?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")). " <br><br>\n ";

$b =new Java ("Test.test");
$x = $b->getmessage ("<br><font Color=red>hello java! I am from php!</font> ");
echo $x;

?>
Show Results:
Java version=1.4.1_01
Java Vendor=sun Microsystems Inc.
Os=windows XP 5.2 on x86
Thursday, January, 2006 at 3:00:51 afternoon 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.