Click to See Complete Forum and Search --> : [RESOLVED] Testing Newly Installed PHP/java Bridge
Paul R
07-16-2006, 01:00 PM
Through the kind help of tsinka, yesterday I installed the PHP Java Bridge. The system checked out on the one test system which did not involve reference to compiled java code.
When I use the java_require or or java_include commands at the beginning of the PHP script to point to the compiled code, I get error messages from the Apache server to the effect that these commands can not be located.
The only thing that works is:
$system = new Java('java.lang.System'); in the original test program.
But, how do I include a custom class that the bridge will recognize?
Paul R
tsinka
07-16-2006, 06:26 PM
Please post the java source, the php source, the current java settings in php.ini and the Java section of the phpinfo() output. Additionally check with the task manager, if there are any javaw.exe processes running.
Thomas
Paul R
07-16-2006, 07:56 PM
Thomas, I tjhink my confusion is about how to write one step in the php program.
Namely line 7 in the paul.php program to call and print the output from the java code.
Here is the java code: (located in c:\javaclasses) compiled as javaprog.class
public class javaprog
{
public static void main(String[] args)
{
System.out.println("Printed by Java program");
System.exit(8) ;
}
}
Next is the php code in htdocs as :
<?php
java_require("C:\javaclasses");
$my = new Java('javaprog');
echo "Hello World!" ;
$output = array();
$return_var = 0;
java javaprog ->($output) //This is the trouble line. I don't know how to do this properly.
$output_str = join($output, "\n");
echo "<pre>The output was:\n$output_str\n\n";
echo "The return value was $return_var</pre>" ;
?>
Note: The two other model programs you sent me work fine!
I think this problem rests on my ignorance and is probably very simple.
Paul R
tsinka
07-16-2006, 08:08 PM
Ok,
the problem is that you wrote a command line java program that uses System.out.println to print something. There's no way to fetch that output. The output gets written to the apache error log (default). Command line java applications (classes) are not really usable with the bridge.
My example classes provide some functions that return values or objects that you can further use.
What kind of application do you want to implement using the PHP/Java bridge ?
Thomas
Paul R
07-17-2006, 10:30 AM
Thomas,
You asked how I plan to use java with PHP. The basic idea is
that PHP will bring information from a client site up to the
server, where it will be inserted into a MySQL database.
PHP/Java code at the server will then be used to fill a java
array with the data. This data is then processed through a
rather complicated java program, resulting in an output of some
numbers. These numbers are to be passed back to the client via
php code. They are also to be stored in the database.
I have been developing the java code using the Eclipse IDE. The
output of the java development is a set of .class files.
It is true that during the development I need to output to the
console for debugging purposes. So,lots of use of
System.out.println. But I will not use these in the final code.
However, I am very concerned with your statement that classes
are not usable with the bridge! I don't know of any other way
to produce java than to have classes, packages, and jars. Could
you clarify?
Thank you,
Paul
tsinka
07-17-2006, 10:54 AM
Sorry,
my post wasn't clear. classes/packages/jars are the way how java works so that won't be a problem. I just wanted to say that a simple command line application that just prints something using System.out.println is a bad example to test the PHP/Java bridge. As long as the classes you want to use return objects or whatever java types that you can use in your php scripts everything will work fine. The debugging output using System.out.println is still ok since the output gets written to the apache error_log. You can then just check the error_log to see if the debug output is ok.
Thomas
Paul R
07-17-2006, 11:15 AM
Thanks again Thomas.
I'll close this thread. I think I can continue ok.
Paul
PHP Builder
Copyright WebMediaBrands Inc. All Rights Reserved.