简体   繁体   中英

Problem in PHP-Java integration using PHP/Java Bridge

I need an urgent help from you people.I got something very odd while trying to integrate PHP with Java. First, my question:

When I start the Apache server service, the program runs ok. But, if I close the browser and open it again, the program no longer runs and give me a "Fatal error: Unable to create Java Virtual Machine in C:\\php\\java.php ..." .

If I restart the Apache server service, the program works again, but with the same behavior: if I close the browser window and open it again, it does not work.

I checked on internet but dont get any solution but found many people facing same problem. And many of them told its a bug in PHP-Java bridge. So is there any solution on this problem. I ran out of options and, if anyone could help, I'll appreciate.

Thank You.

My system specifications:

  • Windows XP

I have installed

  • XAMPP server:- xampp-win32-1.6.1-installer

This install PHP, Apache, and MySQL on my system. There versions are as follows

  • Apache Version :- Apache/2.2.4 (Win32)
  • PHP version :- 4.3.1
  • Sun Microsystems JDK version :- jdk1.6.0_16

I am achieving this PHP-Java extensoion using php-javabridge. I have downloaded javabridge.jar file from following url: http://php-java-bridge.sourceforge.net/pjb/download.php

I placed the downloaded javabridge.jar file on this path: C:\\xampp\\php\\ext\\

Settings done in php.ini file for php-java integration are as follows.

; Directory in which the loadable extensions (modules) reside.
extension_dir = "C:\xampp\php\ext\"

I also uncomment the java extension.

extension=php_java.dll

I have added following lines in Module Settings section of PHP.ini file.

;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;

[Java]
;This points to the directory where your Java 
;classes will be stored.  You can designate multiple
;paths, each path separated by a semicolon.
;It must also include the location of php_java.jar
java.class.path = "C:\xampp\php\ext\JavaBridge.jar;C:\xampp\php\extensions\php_java.jar;C:\Program Files\Java\jdk1.6.0_16\jre\lib;C:\Program Files\Java\jdk1.6.0_16;C:\prog"

;java.class.path = "C:\xampp\php\extensions\php_java.jar;C:\prog"
; This points to the bin directory of the JDK.
java.home = "C:\Program Files\Java\jdk1.6.0_16\bin"

; This must point to the Java Virtual Machine (jvm.dll) file.
java.library = "C:\Program Files\Java\jdk1.6.0_16\jre\bin\server\jvm.dll"

; This must point to the location of php_java.dll.
java.library.path = "C:\xampp\php\ext;C:\Program Files\Java\jdk1.6.0_16\jre\lib"

java.java = "C:\Program Files\Java\jdk1.6.0_16\bin\javaw.exe"

Java class which I am using in PHP script.

import java.util.*;
import java.text.*;

public class SalesTax {

  public String SalesTax(double price, double salesTax) {

    double tax = price * salesTax;

    NumberFormat numberFormatter;

    numberFormatter = NumberFormat.getCurrencyInstance();
    String priceOut = numberFormatter.format(price);
    String taxOut = numberFormatter.format(tax);

    numberFormatter = NumberFormat.getPercentInstance();
    String salesTaxOut = numberFormatter.format(salesTax);

    String str = "A sales Tax of " + salesTaxOut +
                 " on " + priceOut + " equals " + taxOut + ".";

    return str;

    }

}

PHP script test1.php which is using above java class

<?php
// Format the HTML form.
$salesTaxForm = <<<SalesTaxForm
   <form action="test1.php" method="post">
   Price (ex. 42.56):<br>
   <input type="text" name="price" size="15" maxlength="15" value=""><br>
   Sales Tax rate (ex. 0.06):<br>
   <input type="text" name="tax" size="15" maxlength="15" value=""><br>
   <input type="submit" name="submit" value="Calculate!">
   </form>
SalesTaxForm;

if (! isset($_POST[submit])) 
   echo $salesTaxForm;
else 
{
   // Instantiate the SalesTax class.
   $salesTax = new Java("SalesTax");
   // Don't forget to typecast in order to
   // conform with the Java method specifications.
   $price = (double) $_POST[price]; 
   $tax = (double) $_POST[tax];
   print $salesTax->SalesTax($price, $tax);
}
?>

The PHP Java bridge has nothing to do with the extension php_java.dll . The former is a userland PHP implementation.

Please read the docs .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM