Problem to connect PHP with Java class

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

Problem to connect PHP with Java class

Postby jeremycod » 09. December 2007 16:14

Hi,

I have problem to connect PHP with java application using PHP/java bridge. I am using XAMPP 1.6.4 and Tomcat addon. I have created a simple PHP file that instantiate Java class, like:

<?php
$system=new Java('java.lang.System');
?>

If I use php_java.jar and php_java.dll that comes with xampp 1.6.4 installation I got error message:

Fatal error: java() [<a href='function.java'>function.java</a>]: Unable to load Java Library jvm.dll, error: The specified module could not be found. in C:\xampp\htdocs\example.php on line 2

However, phpInfo() gives the following information about Java

java.class.path C:\xampp\php\ext\php_java.jar C:\xampp\php\ext\php_java.jar
java.home C:\Program Files\Java\jdk1.6.0_02 C:\Program Files\Java\jdk1.6.0_02
java.library jvm.dll jvm.dll
java.library.path C:\php\ext C:\php\ext

My php.ini file Java module settings looks as follow

;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;
[java]
java.home="C:\Program Files\Java\jdk1.6.0_02"
java.java="C:\Program Files\Java\jdk1.6.0_02\bin\javaw.exe"
java.class.path="C:\xampp\php\ext\php_java.jar"
java.library.path="C:\php\ext"
java.log_level=3


If I use php-java-bridge_3.2.1 I do not get any information about Java in phpInfo().

Is there any suggestion how to solve this problem?
jeremycod
 
Posts: 6
Joined: 09. December 2007 00:00

Postby Izzy » 09. December 2007 17:15

It would appear that you have more than the php included in XAMPP which, by the way, is compiled as an Apache module in XAMPP.
You have:
C:\php\ext

The XAMPP php ext directory as defined in the xampp\apache\bin\php.ini file is:
C:\xampp\php\ext

Check in your http://localhost/xampp/phpinfo.php for the information that relates to the XAMPP php, including the location of the php.ini file used.

There are also some demo pages for Java, linked in the XAMPP Welcome Page menu, to test your Tomcat installation in XAMPP and if they work then perhaps looking at the files they refer to will provide some php code clues for your own needs.

Also a search for tomcat in the XAMPP for Windows forum under the Category Apache Friends in English may produce some informative results.



===========================================
1. The new DeskTopXampp Launch Control for XAMPP / XAMPPlite
Posted by Ridgewood available from Ridgewood'sDTX web site

2. Build Rich AJAX Applications - Faster
TIBCO General Interface Pro Edition but FREE and Open Source
Fully working with NO donations required to get a user/password
===========================================
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Postby jeremycod » 09. December 2007 21:39

Hi Izzy,


It would appear that you have more than the php included in XAMPP which, by the way, is compiled as an Apache module in XAMPP.
You have:
C:\php\ext

Sorry for my typing error. There is no PHP at C: and the only one is C:\xampp\php

Check in your http://localhost/xampp/phpinfo.php for the information that relates to the XAMPP php, including the location of the php.ini file used.

I have checked it.
Configuration File (php.ini) Path C:\WINDOWS
Loaded Configuration File C:\xampp\php\php.ini

I have also copied the same php.ini to the C:\WINDOWS but nothing does not happened.
There are also some demo pages for Java, linked in the XAMPP Welcome Page menu, to test your Tomcat installation in XAMPP and if they work then perhaps looking at the files they refer to will provide some php code clues for your own needs.

I have tried this. All examples under the Java works fine, but that are JSP pages or servlets, there are no examples for PHP page that uses some Java class.
Do you have some other idea, or some tutorial or code example that I can use to make a basic example that works?

Zoran
jeremycod
 
Posts: 6
Joined: 09. December 2007 00:00

Postby KallistaAEnvarou » 10. December 2007 00:59

Are you using Java or JavaScript? There's a huge difference.
KallistaAEnvarou
 
Posts: 126
Joined: 02. December 2007 17:33
Location: Cold Cold California

Postby jeremycod » 10. December 2007 17:19

KallistaAEnvarou wrote:Are you using Java or JavaScript? There's a huge difference.


I want to use Java application as a background. It's will not be Web application (JSP or servlet), just Java application that contains some methods that I can call from PHP application, pass some values, perform some processing or get values. Maybe it can be implemented as Web service as well. I'm not sure, but I cannot start to work on it because I can't make even a simple HelloWorld application.
jeremycod
 
Posts: 6
Joined: 09. December 2007 00:00

Postby jeremycod » 10. December 2007 19:38

I have installed PHP/Java Bridge. It works fine with provided examples (NumberGuess PHP), but not with my example that is deployed to
the Apache server:

Code: Select all
<?php
if(!extension_loaded("java"))
      require_once("http://localhost:8080/JavaBridge/java/Java.inc");
    $s = new Java("java.lang.String", "hello");
?>


It gives me the error:

Code: Select all
Fatal error: java() [<a href='function.java'>function.java</a>]:
 Unable to load Java Library C:\Program
 Files\Java\jdk1.6.0_02\jre\bin\server, error: The specified module could not be found. in
 C:\xampp\htdocs\example.php on line 7


If I start phpInfo() these values are available:

Code: Select all
 java.class.path  no value  no value   
  java.home  C:\Program Files\Java\jdk1.6.0_02  C:\Program Files\Java\jdk1.6.0_02 
  java.library  jvm.dll  jvm.dll    java.library.path  C:\php\ext  C:\php\ext


Zoran
jeremycod
 
Posts: 6
Joined: 09. December 2007 00:00

Postby KallistaAEnvarou » 10. December 2007 23:14

Well, I'm not going to be much help since I don't have any experience in this area, but maybe you could change

require_once("http://localhost:8080/JavaBridge/java/Java.inc");

to

require_once($_SERVER[DOCUMENT_ROOT] . "/JavaBridge/java/Java.inc");

Apparently that file exists since you're not getting an error there, but maybe you'll have better luck using this string? Or maybe there's a problem with the required file itself?
KallistaAEnvarou
 
Posts: 126
Joined: 02. December 2007 17:33
Location: Cold Cold California

Postby Izzy » 10. December 2007 23:31

Did you uncomment this extension in the xampp\apache\bin\php.ini file?
;extension=php_java.dll
to
extension=php_java.dll
Then restart Apache

I take it you have read the php manual on this subject:
http://php.net/java

BTW php.ini will not be recognized by Apache in any other directory other than the one I have indicated above.

Also check your Windows Environment Variables to make sure your paths are not in conflict - User Variables (logged on user) v System Variables (not logged on user dependent)

I see that c:\php\ext is still being referenced or is this another typo?
This needs to be attended to as it does not exist, as you pointed out before and may be referenced from within your system paths.


===========================================
1. The new DeskTopXampp Launch Control for XAMPP / XAMPPlite
Posted by Ridgewood available from Ridgewood'sDTX web site

2. Build Rich AJAX Applications - Faster
TIBCO General Interface Pro Edition but FREE and Open Source
Fully working with NO donations required to get a user/password
===========================================
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Postby jeremycod » 11. December 2007 00:31

Hi,

Izzy wrote:Did you uncomment this extension in the xampp\apache\bin\php.ini file?
;extension=php_java.dll
to
extension=php_java.dll
Then restart Apache


Yes, I have done it. I'm not sure about which php_java.dll file should I use? I have used the one that came with XAMPP installation (xampp/php/ext/php_java.dll). Do I need to change it with some other specific for PHP/Java Bridge?

BTW php.ini will not be recognized by Apache in any other directory other than the one I have indicated above.

Also check your Windows Environment Variables to make sure your paths are not in conflict - User Variables (logged on user) v System Variables (not logged on user dependent)

php.ini is on in the directory xampp\apache\bin
I do not have any User variables. Here are my system variables:
Code: Select all
CLASSPATH   .
JAVA_HOME   C:\Program Files\Java\jdk1.6.0_02
PATH        %JAVA_HOME%\bin;%SystemRoot%\system32;%SystemRoot%;C:\Program Files\MySQL\MySQL Server 6.0\bin;


and here are my php.ini settings:

Code: Select all
extension=php_java.dll
;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;
[java]
java.hosts = "localhost:8080"
java.servlet = On
java.java_home="C:\Program Files\Java\jdk1.6.0_02\bin"
java.java="C:\Program Files\Java\jdk1.6.0_02\bin\javaw.exe"
java.library="C:\Program Files\Java\jdk1.6.0_02\jre\bin\server\jvm.dll"
java.library.path="C:\xampp\php\ext; C:\Program Files\Java\jdk1.6.0_02\lib"
java.class.path="C:\xampp\php\ext\JavaBridge.jar; C:\Program Files\Java\jdk1.6.0_02\lib"
java.log_level=2


Now, I'm getting message "Internet Explorer cannot display the webpage...".

Zoran
jeremycod
 
Posts: 6
Joined: 09. December 2007 00:00

Postby Izzy » 11. December 2007 01:14

Yes, I have done it. I'm not sure about which php_java.dll file should I use? I have used the one that came with XAMPP installation (xampp/php/ext/php_java.dll). Do I need to change it with some other specific for PHP/Java Bridge?

The path to the uncommented extensions are defined in the php.ini file - make sure it is a full path and not just a relative path.

You would have to ask on the PHP/Java Bridge site about their needs.

And make sure that tomcat is running - preferably as a service.

No guarantee this will work but try adding these paths to your System Variable Path in this order:

Code: Select all
C:\xampp\tomcat;C:\xampp\php;C:\xampp\apache\bin;%JAVA_HOME%\bin;%SystemRoot%\system32;%SystemRoot%


Note there is no ; at the end of the variable line as this only indicates that another path follows.

You can add as many paths you feel will help your cause - my Path statement is about 2 miles long and it won't hurt to duplicate the paths you add into the User variable for you PATH variable.

Also you have another instance of MySQL in the system path that I would remove, as XAMPP also contains a MySQL instance and this may cause issues or confusion perhaps, especially if you don't use it - as you would normally use PHP and MySQL from within XAMPP.
(Is there a php.ini file in the MySQL bin directory mentioned in the path variables?)

Other than all the above details I am at a loss to know what else for you to do - but some more knowledgeable forum member might know of other ideas that may help you.
Good luck.


===========================================
1. The new DeskTopXampp Launch Control for XAMPP / XAMPPlite
Posted by Ridgewood available from Ridgewood'sDTX web site

2. Build Rich AJAX Applications - Faster
TIBCO General Interface Pro Edition but FREE and Open Source
Fully working with NO donations required to get a user/password
===========================================
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Postby jeremycod » 11. December 2007 20:13

Hi,

I have tried everything from begining, removed MySQL server and XAMPP, install xamp, set everything again as in the tutorial, and I'm always getting error

Code: Select all
Fatal error: java() [<a href='function.java'>function.java</a>]: Unable to load Java Library jvm.dll, error: The specified module could not be found. in C:\xampp\htdocs\myApp\test.php on line 4


when trying to start php page
Code: Select all
<?php
if(!extension_loaded("java"))
    require_once("http://localhost:8080/JavaBridge/java/Java.inc");
    $s = new Java("java.lang.String", "hello");
?>


However, if I start test.bat from PHP/Java bridge, I'm getting the following error concerning php-cgi:

Code: Select all
Invoking php: [php-cgi, -n, -d, allow_url_include=On, F:\Materijali za doktorski
 rad\instalacije\PHP\PHP-Java Bridge\php-java-bridge_4.3.1a_j2ee2\test.php]
java.lang.RuntimeException: Could not run PHP ([php-cgi, -n, -d, allow_url_inclu
de=On, F:\Materijali za doktorski rad\instalacije\PHP\PHP-Java Bridge\php-java-b
ridge_4.3.1a_j2ee2\test.php]), please check if php-cgi is in the path.
        at TestInstallation.start(TestInstallation.java:319)
        at TestInstallation.main(TestInstallation.java:243)
Caused by: java.io.IOException: Cannot run program "php-cgi": CreateProcess erro
r=2, The system cannot find the file specified
        at java.lang.ProcessBuilder.start(Unknown Source)
        at java.lang.Runtime.exec(Unknown Source)
        at java.lang.Runtime.exec(Unknown Source)
        at TestInstallation.start(TestInstallation.java:317)
        ... 1 more
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified


I suppose that I should set the path to the php-cgi, so I have done it at the system PATH "C://xamp/php"
and in php.ini

[java]
java.hosts="127.0.0.1:8080"
java.servlet=User
java.library.path="C:\xampp\php\ext"

I have also checked allow_url_include=On in php.ini and it is set to On.

Zoran
jeremycod
 
Posts: 6
Joined: 09. December 2007 00:00


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 129 guests