gpt4 book ai didi

java - 使用 PHP/Java Bridge 进行 PHP-Java 集成的问题

转载 作者:行者123 更新时间:2023-12-01 05:54:02 26 4
gpt4 key购买 nike

我需要你们的紧急帮助。在尝试将 PHP 与 Java 集成时,我遇到了一些非常奇怪的事情。首先,我的问题:

当我启动Apache服务器服务时,程序运行正常。但是,如果我关闭浏览器并再次打开它,程序不再运行并给我一个“ fatal error :无法在 C:\php\java.php ... 中创建 Java 虚拟机...”

如果我重新启动 Apache 服务器服务,程序会再次运行,但行为相同:如果我关闭浏览器窗口并再次打开它,程序将无法运行。

我在互联网上查了一下,但没有得到任何解决方案,但发现很多人面临同样的问题。他们中的许多人都说这是 PHP-Java 桥接中的一个错误。那么对于这个问题有没有什么解决办法呢。我已经没有选择了,如果有人可以提供帮助,我将不胜感激。

谢谢。

我的系统规范:

  • Windows XP

我已经安装

  • XAMPP 服务器:- xampp-win32-1.6.1-installer

这会在我的系统上安装 PHP、Apache 和 MySQL。有版本如下

  • Apache 版本:- 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 ;
;;;;;;;;;;;;;;;;;;;

[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 类。

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 使用上面的 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);
}
?>

最佳答案

PHP Java 桥与扩展 php_java.dll 无关。前者是用户态 PHP 实现。

请阅读the docs .

关于java - 使用 PHP/Java Bridge 进行 PHP-Java 集成的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3657785/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com