By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,533 Members | 1,497 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,533 IT Pros & Developers. It's quick & easy.

PHP and Java

P: n/a
I am trying to get Java to work from within PHP. I have been looking at:
http://us2.php.net/java

The error and line of PHP code:
$system = new Java('java.lang.System');

Fatal error: Class 'Java' not found in C:\Documents and Settings\Ed
Taylor\My Documents\Projects Eclipse\workspaces\workspace
PHP\Scrapboard\JavaExample.php on line 3

I have looked at the 'User Contributed Notes'. It seems there is a
proliferative of different way people have defined the Java
configuration options. Some have links in quotes some do not. Not sure
if I am suppose to use the eight byte Windows dir name?

I am a Java programmer. Sun's JAVA_HOME points to the base directory
name for the JDK installed. In PHP it looks like it points to the bin
subdirectory.

This is what is documented:

java.class.path The path and name of the PHP jar file (usually called
php_java.jar) as well as any other jar files or
directories where PHP will search for compiled
Java classes.
java.home The root directory of the installed JDK
java.library The location of the Java virtual machine library
java.library.path The location of the PHP java library (usually in the
modules/ directory)

This is what I have defined in my PHP.ini:

extension=php_java.dll

java.class.path = "C:\php5.2\ext\php_java.jar"
java.home = "C:\Program Files\Java\jdk1.5.0_07"
java.library = "C:\Program
Files\Java\jdk1.5.0_07\jre\bin\server\jvm.lib"
java.library.path = "C:\php5.2\ext"
I am running:
- Windoze XP SP 2
- PHP 5.2
- Java JDK and JRE 1.5.0_07
- Eclipse 3.2
- PHPEclipse 0.2.0

Anyone point me in the right direction.

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Jul 30 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
IchBin wrote:
I am trying to get Java to work from within PHP. I have been looking at:
http://us2.php.net/java

The error and line of PHP code:
$system = new Java('java.lang.System');

Fatal error: Class 'Java' not found in C:\Documents and Settings\Ed
Taylor\My Documents\Projects Eclipse\workspaces\workspace
PHP\Scrapboard\JavaExample.php on line 3
PHP can't find a class definition - the PECL extension isn't loaded. You can
confirm this using phpinfo()
This is what I have defined in my PHP.ini:

extension=php_java.dll

java.class.path = "C:\php5.2\ext\php_java.jar"
java.home = "C:\Program Files\Java\jdk1.5.0_07"
java.library = "C:\Program
Files\Java\jdk1.5.0_07\jre\bin\server\jvm.lib"
java.library.path = "C:\php5.2\ext"
Not used the Java wrapper - typically if PHP can't load an extension it
tells you (You may need to crank up the default volume on error reporting):
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/lib/php5/extensions/libnonesuch.so'
- /usr/lib/php5/extensions/libnonesuch.so: cannot open shared object file:
No such file or directory in Unknown on line 0

HTH

C.
Aug 2 '06 #2

P: n/a
Colin McKinnon wrote:
IchBin wrote:
>I am trying to get Java to work from within PHP. I have been looking at:
http://us2.php.net/java

The error and line of PHP code:
$system = new Java('java.lang.System');

Fatal error: Class 'Java' not found in C:\Documents and Settings\Ed
Taylor\My Documents\Projects Eclipse\workspaces\workspace
PHP\Scrapboard\JavaExample.php on line 3

PHP can't find a class definition - the PECL extension isn't loaded. You can
confirm this using phpinfo()
>This is what I have defined in my PHP.ini:

extension=php_java.dll

java.class.path = "C:\php5.2\ext\php_java.jar"
java.home = "C:\Program Files\Java\jdk1.5.0_07"
java.library = "C:\Program
Files\Java\jdk1.5.0_07\jre\bin\server\jvm.lib"
java.library.path = "C:\php5.2\ext"

Not used the Java wrapper - typically if PHP can't load an extension it
Not sure what you mean when you say you have not used the Java wrapper?
Is there some other way of running Java from with in PHP? This is the
only way I have found how to do it.
tells you (You may need to crank up the default volume on error reporting):
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/lib/php5/extensions/libnonesuch.so'
- /usr/lib/php5/extensions/libnonesuch.so: cannot open shared object file:
No such file or directory in Unknown on line 0
I have changes some of the Error recording parms and when I start Apache
or run a command line I get the following error:

C:\>php-cgi
PHP Warning: PHP Startup: java: Unable to initialize module
Module compiled with module API=20050922, debug=0, thread-safety=1
PHP compiled with module API=20060613, debug=0, thread-safety=1
These options need to match
in Unknown on line 0
<br />
<b>Warning</b>: PHP Startup: java: Unable to initialize module
Module compiled with module API=20050922, debug=0, thread-safety=1
PHP compiled with module API=20060613, debug=0, thread-safety=1
These options need to match
in <b>Unknown</bon line <b>0</b><br />A
>
HTH

C.
The error does not say it can not load it but it can not initialize it.
Just wondering what the difference is and what I am missing. It has to
be a link in the PHP.ini. I'll go back over it with give it another try.

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Aug 2 '06 #3

P: n/a
Colin McKinnon wrote:
IchBin wrote:
>I am trying to get Java to work from within PHP. I have been looking at:
http://us2.php.net/java

The error and line of PHP code:
$system = new Java('java.lang.System');

Fatal error: Class 'Java' not found in C:\Documents and Settings\Ed
Taylor\My Documents\Projects Eclipse\workspaces\workspace
PHP\Scrapboard\JavaExample.php on line 3

PHP can't find a class definition - the PECL extension isn't loaded. You can
confirm this using phpinfo()
>This is what I have defined in my PHP.ini:

extension=php_java.dll

java.class.path = "C:\php5.2\ext\php_java.jar"
java.home = "C:\Program Files\Java\jdk1.5.0_07"
java.library = "C:\Program
Files\Java\jdk1.5.0_07\jre\bin\server\jvm.lib"
java.library.path = "C:\php5.2\ext"

Not used the Java wrapper - typically if PHP can't load an extension it
tells you (You may need to crank up the default volume on error reporting):
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/lib/php5/extensions/libnonesuch.so'
- /usr/lib/php5/extensions/libnonesuch.so: cannot open shared object file:
No such file or directory in Unknown on line 0

HTH

C.
Not sure what you mean when you say you have not used the Java wrapper?
Is there some other way of running Java from with in PHP? I do not mean
PHP from with in Java. This is the only way I have found how to do it.

I did not see anything related to Java in the phpinfo(). I do have two
file in the .ext subdirectory:

php_java.jar
php_java.dll

I have changes some of the Error recording parms and when I start Apache
or run a command line I get the following error:

C:\>php-cgi
PHP Warning: PHP Startup: java: Unable to initialize module
Module compiled with module API=20050922, debug=0, thread-safety=1
PHP compiled with module API=20060613, debug=0, thread-safety=1
These options need to match
in Unknown on line 0
<br />
<b>Warning</b>: PHP Startup: java: Unable to initialize module
Module compiled with module API=20050922, debug=0, thread-safety=1
PHP compiled with module API=20060613, debug=0, thread-safety=1
These options need to match
in <b>Unknown</bon line <b>0</b><br />A

The error does not say it can not load it but it can not initialize it.
Just wondering what the difference is and what I am missing. It has to
be a link in the PHP.ini. I'll go back over it with give it another try.

Keeping my feet in Java and new to PHP I think that this should be
top-down process to implement. The user comments in the extended PHP
manual for Java does not give me much of a secure feeling.

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Aug 2 '06 #4

P: n/a
IchBin wrote:
Colin McKinnon wrote:
>IchBin wrote:
>>I am trying to get Java to work from within PHP. I have been looking at:
http://us2.php.net/java

The error and line of PHP code:
$system = new Java('java.lang.System');

Fatal error: Class 'Java' not found in C:\Documents and Settings\Ed
Taylor\My Documents\Projects Eclipse\workspaces\workspace
PHP\Scrapboard\JavaExample.php on line 3

PHP can't find a class definition - the PECL extension isn't loaded.
You can
confirm this using phpinfo()

>>This is what I have defined in my PHP.ini:

extension=php_java.dll

java.class.path = "C:\php5.2\ext\php_java.jar"
java.home = "C:\Program Files\Java\jdk1.5.0_07"
java.library = "C:\Program
Files\Java\jdk1.5.0_07\jre\bin\server\jvm.lib"
java.library.path = "C:\php5.2\ext"

Not used the Java wrapper - typically if PHP can't load an extension it


Not sure what you mean when you say you have not used the Java wrapper?
Is there some other way of running Java from with in PHP? This is the
only way I have found how to do it.
>tells you (You may need to crank up the default volume on error
reporting):
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/lib/php5/extensions/libnonesuch.so'
- /usr/lib/php5/extensions/libnonesuch.so: cannot open shared object
file:
No such file or directory in Unknown on line 0


I have changes some of the Error recording parms and when I start Apache
or run a command line I get the following error:

C:\>php-cgi
PHP Warning: PHP Startup: java: Unable to initialize module
Module compiled with module API=20050922, debug=0, thread-safety=1
PHP compiled with module API=20060613, debug=0, thread-safety=1
These options need to match
in Unknown on line 0
<br />
<b>Warning</b>: PHP Startup: java: Unable to initialize module
Module compiled with module API=20050922, debug=0, thread-safety=1
PHP compiled with module API=20060613, debug=0, thread-safety=1
These options need to match
in <b>Unknown</bon line <b>0</b><br />A
>
HTH
>
C.

The error does not say it can not load it but it can not initialize it.
Just wondering what the difference is and what I am missing. It has to
be a link in the PHP.ini. I'll go back over it with give it another try.

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
It means the Java wrapper and PHP have been compiled against two
different versions of Apache API. You'll either need to find matching
versions or compile your own.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 3 '06 #5

P: n/a
Jerry Stuckle wrote:
IchBin wrote:
>Colin McKinnon wrote:
>>IchBin wrote:

I am trying to get Java to work from within PHP. I have been looking
at:
http://us2.php.net/java

The error and line of PHP code:
$system = new Java('java.lang.System');

Fatal error: Class 'Java' not found in C:\Documents and Settings\Ed
Taylor\My Documents\Projects Eclipse\workspaces\workspace
PHP\Scrapboard\JavaExample.php on line 3
PHP can't find a class definition - the PECL extension isn't loaded.
You can
confirm this using phpinfo()
This is what I have defined in my PHP.ini:

extension=php_java.dll

java.class.path = "C:\php5.2\ext\php_java.jar"
java.home = "C:\Program Files\Java\jdk1.5.0_07"
java.library = "C:\Program
Files\Java\jdk1.5.0_07\jre\bin\server\jvm.lib "
java.library.path = "C:\php5.2\ext"
Not used the Java wrapper - typically if PHP can't load an extension it


Not sure what you mean when you say you have not used the Java
wrapper? Is there some other way of running Java from with in PHP?
This is the only way I have found how to do it.
>>tells you (You may need to crank up the default volume on error
reporting):
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/lib/php5/extensions/libnonesuch.so'
- /usr/lib/php5/extensions/libnonesuch.so: cannot open shared object
file:
No such file or directory in Unknown on line 0


I have changes some of the Error recording parms and when I start
Apache or run a command line I get the following error:

C:\>php-cgi
PHP Warning: PHP Startup: java: Unable to initialize module
Module compiled with module API=20050922, debug=0, thread-safety=1
PHP compiled with module API=20060613, debug=0, thread-safety=1
These options need to match
in Unknown on line 0
<br />
<b>Warning</b>: PHP Startup: java: Unable to initialize module
Module compiled with module API=20050922, debug=0, thread-safety=1
PHP compiled with module API=20060613, debug=0, thread-safety=1
These options need to match
in <b>Unknown</bon line <b>0</b><br />A
> >
HTH

C.

The error does not say it can not load it but it can not initialize
it. Just wondering what the difference is and what I am missing. It
has to be a link in the PHP.ini. I'll go back over it with give it
another try.

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
_________________________________________________ _________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)

It means the Java wrapper and PHP have been compiled against two
different versions of Apache API. You'll either need to find matching
versions or compile your own.
Disclaimer: I am new to PHP.

Well I was running on PHP 5.2.0Dev when I was testing the Java modules
before. So I when back to PHP version 5.1.4. PHP now gives me no
initialize errors. Have not tested php scripts completely.

*Now* the problems is that I can not install PEAR. I get 2 errors "CLI
has encountered a problem and needs to close. We are sorry for the
inconvenience."

I had no problem installing it on PHP 5.2.0Dev. After I installed pear I
download and installed 4 modules I want to use. I did notice that on the
dev version the pear dir structure was 'PHP\PEAR\pear'. Now on 5.1.4 the
structure is 'PHP\PEAR\PEAR'.

I clean up the system of all the prior PHP\Pear install even the
registry. I do not understand.... Is this environment so fickled that I
can go back to a stable version of PHP and I can not install an
important part as PEAR but still have it work on a Dev version of PHP.?

Very frustrating...

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Aug 4 '06 #6

P: n/a

If your project isn't too far along the best experience I've had with
Java and PHP interop is with Caucho Resin. Very fast, very stable, can
create server-side code in Java, JS, PHP, with simple Java-based PHP
extension mechanisms. Really good stuff.

Cheers,
Yong
IchBin wrote:
Colin McKinnon wrote:
IchBin wrote:
I am trying to get Java to work from within PHP. I have been looking at:
http://us2.php.net/java

The error and line of PHP code:
$system = new Java('java.lang.System');

Fatal error: Class 'Java' not found in C:\Documents and Settings\Ed
Taylor\My Documents\Projects Eclipse\workspaces\workspace
PHP\Scrapboard\JavaExample.php on line 3
PHP can't find a class definition - the PECL extension isn't loaded. You can
confirm this using phpinfo()
This is what I have defined in my PHP.ini:

extension=php_java.dll

java.class.path = "C:\php5.2\ext\php_java.jar"
java.home = "C:\Program Files\Java\jdk1.5.0_07"
java.library = "C:\Program
Files\Java\jdk1.5.0_07\jre\bin\server\jvm.lib"
java.library.path = "C:\php5.2\ext"
Not used the Java wrapper - typically if PHP can't load an extension it

Not sure what you mean when you say you have not used the Java wrapper?
Is there some other way of running Java from with in PHP? This is the
only way I have found how to do it.
tells you (You may need to crank up the default volume on error reporting):
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/lib/php5/extensions/libnonesuch.so'
- /usr/lib/php5/extensions/libnonesuch.so: cannot open shared object file:
No such file or directory in Unknown on line 0

I have changes some of the Error recording parms and when I start Apache
or run a command line I get the following error:

C:\>php-cgi
PHP Warning: PHP Startup: java: Unable to initialize module
Module compiled with module API=20050922, debug=0, thread-safety=1
PHP compiled with module API=20060613, debug=0, thread-safety=1
These options need to match
in Unknown on line 0
<br />
<b>Warning</b>: PHP Startup: java: Unable to initialize module
Module compiled with module API=20050922, debug=0, thread-safety=1
PHP compiled with module API=20060613, debug=0, thread-safety=1
These options need to match
in <b>Unknown</bon line <b>0</b><br />A
>
HTH
>
C.

The error does not say it can not load it but it can not initialize it.
Just wondering what the difference is and what I am missing. It has to
be a link in the PHP.ini. I'll go back over it with give it another try.

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Aug 4 '06 #7

P: n/a
ybakos wrote:
If your project isn't too far along the best experience I've had with
Java and PHP interop is with Caucho Resin. Very fast, very stable, can
create server-side code in Java, JS, PHP, with simple Java-based PHP
extension mechanisms. Really good stuff.

Cheers,
Yong
IchBin wrote:
>Colin McKinnon wrote:
>>IchBin wrote:

I am trying to get Java to work from within PHP. I have been looking at:
http://us2.php.net/java

The error and line of PHP code:
$system = new Java('java.lang.System');

Fatal error: Class 'Java' not found in C:\Documents and Settings\Ed
Taylor\My Documents\Projects Eclipse\workspaces\workspace
PHP\Scrapboard\JavaExample.php on line 3

PHP can't find a class definition - the PECL extension isn't loaded. You can
confirm this using phpinfo()

This is what I have defined in my PHP.ini:

extension=php_java.dll

java.class.path = "C:\php5.2\ext\php_java.jar"
java.home = "C:\Program Files\Java\jdk1.5.0_07"
java.library = "C:\Program
Files\Java\jdk1.5.0_07\jre\bin\server\jvm.lib "
java.library.path = "C:\php5.2\ext"

Not used the Java wrapper - typically if PHP can't load an extension it
Not sure what you mean when you say you have not used the Java wrapper?
Is there some other way of running Java from with in PHP? This is the
only way I have found how to do it.
>>tells you (You may need to crank up the default volume on error reporting):
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/lib/php5/extensions/libnonesuch.so'
- /usr/lib/php5/extensions/libnonesuch.so: cannot open shared object file:
No such file or directory in Unknown on line 0
I have changes some of the Error recording parms and when I start Apache
or run a command line I get the following error:

C:\>php-cgi
PHP Warning: PHP Startup: java: Unable to initialize module
Module compiled with module API=20050922, debug=0, thread-safety=1
PHP compiled with module API=20060613, debug=0, thread-safety=1
These options need to match
in Unknown on line 0
<br />
<b>Warning</b>: PHP Startup: java: Unable to initialize module
Module compiled with module API=20050922, debug=0, thread-safety=1
PHP compiled with module API=20060613, debug=0, thread-safety=1
These options need to match
in <b>Unknown</bon line <b>0</b><br />A
> >
HTH

C.

The error does not say it can not load it but it can not initialize it.
Just wondering what the difference is and what I am missing. It has to
be a link in the PHP.ini. I'll go back over it with give it another try.

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
_________________________________________________ _________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Thanks for the tip but why do a lot of people in the PHP forums top
post. It really screws up the continuity of the thread.

I am a Java programmer just wanting to learn PHP. So there is no project
involved.

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Aug 4 '06 #8

P: n/a
IchBin wrote:
>>

Thanks for the tip but why do a lot of people in the PHP forums top
post. It really screws up the continuity of the thread.

I am a Java programmer just wanting to learn PHP. So there is no project
involved.

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Mostly because they don't know any better. Many also post from Google
Groups.

I've found a kind request not to top post when responding helps a lot.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 5 '06 #9

P: n/a
Jerry Stuckle wrote:
IchBin wrote:
>>>

Thanks for the tip but why do a lot of people in the PHP forums top
post. It really screws up the continuity of the thread.

I am a Java programmer just wanting to learn PHP. So there is no
project involved.

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
_________________________________________________ _________________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)

Mostly because they don't know any better. Many also post from Google
Groups.

I've found a kind request not to top post when responding helps a lot.
Cool...

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Aug 5 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.