How to do PHP Java integration using phpjava bridge

Problems with the Windows version of XAMPP, questions, comments, and anything related.

How to do PHP Java integration using phpjava bridge

Postby sandipkalal » 08. September 2010 15:01

Hello Friends,
I need an urgent help from you people.
I got something very odd while trying to integrate php with java. First, 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) DAV/2 mod_ssl/2.2.4 OpenSSL/0.9.8e mod_autoindex_color PHP/5.2.1
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.


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

I also uncommented the java extension.

extension=php_java.dll


;;;;;;;;;;;;;;;;;;;
; 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 we will going to use 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);

endif;

?>


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.
sandipkalal
 
Posts: 1
Joined: 08. September 2010 14:15

Re: How to do PHP Java integration using phpjava bridge

Postby BigWetDog » 08. September 2010 15:23

this isn't really an xampp issues, but...
did you follow this: http://php-java-bridge.sourceforge.net/ ... lation.php
It looks like to me you need the Tomcat add-on for xampp.
User avatar
BigWetDog
 
Posts: 148
Joined: 25. February 2010 15:54

Re: How to do PHP Java integration using phpjava bridge

Postby clarkden » 27. September 2010 23:35

sandipkalal wrote:Hello Friends,
I need an urgent help from you people.
I got something very odd while trying to integrate php with java. First, 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) DAV/2 mod_ssl/2.2.4 OpenSSL/0.9.8e mod_autoindex_color PHP/5.2.1
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.


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

I also uncommented the java extension.

extension=php_java.dll


;;;;;;;;;;;;;;;;;;;
; 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 we will going to use 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);

endif;

?>


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.



Hello Sandipkalal
i don't have any knowledge about this, but my friend know about that i will give u the answer after
consulting him.
ok

Clarkden
clarkden
 
Posts: 1
Joined: 27. September 2010 23:28


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 47 guests