2010-09-07 102 views
1

我需要你們的緊急幫助people.I嘗試將PHP與Java集成時出現了一些非常奇怪的現象。首先,我的問題:使用PHP/Java Bridge的PHP-Java集成中的問題

當我啓動Apache服務器服務時,程序運行正常。但是,如果我關閉瀏覽器並再次打開, 該程序不再運行,並給我一個"Fatal error: Unable to create Java Virtual Machine in C:\php\java.php ..."

如果我重新啓動Apache服務器服務,該程序再次工作,但具有相同的行爲:如果關閉瀏覽器窗口並再次打開它,則不起作用。

我在互聯網上查過,但沒有得到任何解決方案,但發現很多人面臨同樣的問題。其中許多人告訴它在PHP-Java橋中存在一個錯誤。那麼在這個問題上有什麼解決方案。我用盡了選擇,如果有人可以幫忙,我會感激。

謝謝。

我的系統規格:

  • 的Windows XP

我已經安裝了

  • XAMPP服務器: - XAMPP-win32-1.6.1的安裝程序

這會在我的系統上安裝PHP,Apache和MySQL。有版本如下

  • Apache的版本: - 阿帕奇/ 2.2.4(Win32的)
  • PHP版本: - 4.3.1
  • Sun Microsystems的JDK版本: - jdk1.6.0_16

我正在使用php-javabridge實現這個PHP-Java擴展。我從以下網址下載javabridge.jar文件:http://php-java-bridge.sourceforge.net/pjb/download.php

我把這個路徑上的下載javabridge.jar文件:是C:\xampp\php\ext\

在php.ini文件中做了PHP,Java集成設置如下。

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

I also uncomment the java extension. 

extension=php_java.dll 

我在PHP.ini文件的Module Settings部分添加了以下行。

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

我在PHP腳本中使用的Java類。這是使用上面的Java類

<?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); 
} 
?> 
+0

再說一次,當你說Java時,請不要大喊。 – Joset 2010-09-07 10:30:07

+0

嗨Joset!我不明白你到底想說什麼。 – 2010-09-07 11:30:02

回答

0

PHP Java Bridge爲

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腳本test1.php無關與擴展php_java.dll。前者是一個用戶級PHP實現。請參閱the docs

+0

你好Artefacto!謝謝您的回答。我將從php.ini文件中刪除php_java.dll路徑,但請在「無法創建Java虛擬機問題」中指導我。 – 2010-09-08 08:05:18