Hi,

I'm having trouble getting PHP (Version 4.0.1pl2) to work with Java support. I have configured the PHP configuration '--with-java' etc, and added the appropriate lines to php.ini as instructed in the php-path/ext/java/README file:

========================================================================

=== JVM=Blackdown 1.2.2 RC4, OS=Redhat Linux 6.1 ===

build instructions:

./configure --with-java

php.ini:

[java]
java.class.path=/home/rubys/php4/lib/php_java.jar
extension_dir=/home/rubys/php4/modules
extension=libphp_java.so

...(using my own system's paths, of course, which I have tested). I was able to rebuild and configure PHP without any errors, but when I try to do something like:

$foo = new java("objectname");

I get this frustrating error:

Fatal error: Unable to load Java Library /usr/local/jdk1.2.2/jre/lib/i386/libjava.so in
/filepath/test.php4 on line 8

The libjava.so file is definitely THERE, at the path listed in the error, and it is world-readable and executable.

So does anyone know why am I getting this error? Java is working fine from the command line.

Any ideas?

Thanks,

Luke

    8 days later

    Luke:

    I've got the same setup you describe and am getting precisely the same error.

    There seems to be little documentation on exactly what's going on with the whole PHP/Java thing at this point, although Sam Ruby has written various bits and pieces here and there (thanks for all your work on this, Sam!).

    If anyone can provide further help with this problem in particular it would really be terrific.

    Regards,

    Jonathan

      hey,

      i had the same problrm with the same setup,
      the frustrating part is that the error message is void of useful information
      so i changed the java.c file to give some useful info:

      if (javalib) {
      dl_handle = DL_LOAD(javalib);

      if (!dl_handle) {
        php_error(E_ERROR, "Unable to load Java Library %s", javalib);
        return -1;
      }

      }

      into:

      if (javalib) {
      dl_handle = DL_LOAD(javalib);

      if (!dl_handle) {
        php_error(E_ERROR, "Unable to load Java Library %s, with error %s", javalib, dlerror()); # <== give info
        return -1;
      }

      }

      now you could put the .so 's that it asks for in your ld.so.conf for example
      run ldconfig and away you go

      greetings,
      wouter

        Thanks for the tip, 'wouter.'

        By following your suggestions I've been able to provide php the modules it was looking for in order to load Java. However, I'm kind of back to square one now, because I get the following error:

        Fatal error: Unable to create Java Virtual Machine in /usr/local/apache/htdocs/jver.php on line 4

        Any chance you can tell me what jdk you're using, and something about how you've got it setup?

        Regards,

        Jonathan

          hey jonathan,

          glad i could help you out a little,
          the Fatal error you describe i have seen many times,
          not to worry, it's probably just a matter of misconfiguration, here is a spec of how i have it setup
          for the moment:

          blackdown jdk1.2.2rc4
          php-4.01pl2

          php.ini:
          [java]
          ; blackdown jdk1.2.2
          java.class.path=/usr/local/src/php-4.0.1pl2/ext/java/php_java.jar:/usr/local/java-extras/mm.mysql-2.0.2-bin.jar:/usr/local/jdk1.2.2/jre/lib/rt.jar:/usr/local/jdk1.2.2/lib/tools.jar:/usr/local/JSDK2.0/lib/jsdk.jar:/usr/local/java-extras/xerces.jar:.
          java.home=/usr/local/jdk1.2.2
          java.library.path=/usr/local/src/php-4.0.1pl2/ext/java:/usr/local/src/php-4.0.1pl2/modules:/usr/local/jdk1.2.2/jre/lib:/usr/local/jdk1.2.2/jre/lib/i386/native_threads:/usr/local/jdk1.2.2/jre/lib/i386/classic
          extension_dir=/usr/local/src/php-4.0.1pl2/modules
          extension=libphp_java.so

            wouter:

            Once again, thanks for your helpful info. Sadly, I'm still getting the same fatal error.

            I seem to have almost exactly the same config as you, with two noticable differences.

            The first is that I'm using blackdown jdk1.2.2FCS, which is slightly newer than RC4. However, I did try with RC4 as well, and it didn't work that way either.

            The other difference is that in your php.ini, you provide paths to a dir called JSDK2.0, which contains an archive called jsdk.jar. I have no such files after installing the blackdown jdk -- are you using tools from Sun as well as blackdown? Or have you renamed something? Where does the jsdk.jar file come from?

            Jonathan

              a month later

              Hi,
              I am running Apache 1.3.12, php4.02, IBM JDK1.3 on Redhat 6.2.

              <?$myObject= new Java("java.lang.System"); ?>

              GOT THIS ERROR:
              Can't find class java.lang.NoClassDefFoundError. Invalid class path?

              MY PHP.INI:

              java.class.path
              /usr/local/lib:/usr/local/lib/php_java.jar:usr/local/apache/htdocs:/usr/local/IBMJava2-13/jre/lib/rt.jar:/usr/local/ibm/IBMJava2-13/jre/lib/tools.jar:/usr/local/IBMJava2-13/jre/bin:/usr/local/IBMJava2-13/jre/lib

              java.home
              /usr/local/ibm/IBMJava2-13

              java.library
              libjava.so

              java.library.path
              /usr/local/lib:/usr/local/ibm/IBMJava2-13/jre/bin:/usr/local/ibm/IBMJava2-13/jre/bin/classic

                Hi,

                Yep, the problem is that you either don't have a CLASSPATH variable set up at all, or if you do, it doesn't have the necessary directories in it.

                The code you tried to run worked fine for me. Make sure you have
                CLASSPATH set up properly - use the PHP function phpinfo() to
                see which environment variables are visible to PHP.
                You should at least have
                /usr/local/jdk1.2.2/jre/lib (or whatever your jre lib dir is)
                in your CLASSPATH variable.

                Absolutely all problems I encountered when setting up PHP-Java integration involved paths not being correctly set up.

                Here is what I have in my php.ini file (I am using the Blackdown JDK 1.2.2;
                note that different releases need different setups - see the ext/java/README file for build-specific instructions):

                [java]
                java.class.path=[PATH TO MY PHP SOURCE]/ext/java/php_java.jar
                java.library.path=[PATH TO MY PHP SOURCE]/modules/
                extension_dir=[PATH TO MY PHP SOURCE]/modules/
                extension=libphp_java.so

                I received a very helpful email from someone at oreilly.com on this subject (bless their hearts), which I will quote some of here:

                Turns out it was a path issue -- executing "ldd libjava.so in
                /path/to/java/jre/lib/i386 and see if any modules are listed as not found.
                Find these and add the appropriate directories to your LD_LIBRARY_PATH
                and restart apache.

                I hope this helps.

                -Luke

                  Luke,

                  Good news!
                  The NoClassFound error disappeared.

                  Bad news!
                  No error, No response, eventually time-out.
                  port80 hang. dead server.

                  #apachectl stop does not kill the jvm pid.
                  #kill -SIGKILL pid did the job.
                  #apachectl start

                  Server is now alive. Still can not call java class.

                  Please help.

                  Apache 1.3.12,PHP4.02,IBMJDK1.3

                    Hmmm...hard to say exactly what's going wrong when you aren't getting any errors at all. The Java Virtual Machine seems to be working - it wouldn't have given you the ClassDefNotFOund error if it wasn't. Maybe you just aren't seeing the output from the script - try running it from the command line. Make sure you are only doing something simple to start with...try running the test script in the ext/java dir that prints the date and time.

                    Finally, try putting
                    error_reporting(15);
                    at the top of your PHP script...that sometimes helps.

                    Good luck,

                    Luke

                      a month later

                      Hai,

                      This is the same problem I have with IBM's JDK. Note that using the
                      Blackdown 1.2.2 JDK does not produce this hang (if you check the apache
                      error log you might see that there appears to be an infinite loop trying to load
                      the JVM). This seems to be something specific to the IBM JDKs. If you can, I'd
                      suggest trying the Blackdown JDK.

                      Alex

                        Write a Reply...