I have tried many different settings to get php+Apache server to recognize java.
In particular, I have modified the php.ini file as instructed, as well as the environment variables in Windows XP.
I can run php and Apache together successfully.

I am using Windows XP, Java version jdk1.5.0_06, Apache version 2.0.55, and PHP version 5.1.4
If you need the details of the settings I will be happy to send the variables and new pHP.ini entries.
When I try to run a simple java program, I get the following:
Fatal Error:Class 'Java' not found in c:\program files\apache group\apache2\htdocs\simplejava.php
I think others have had similar problems over the years.
Thank you for taking time to respond.
Paul R

    What exactly are you trying to do?

    Are you trying to get an applet to display in your browser? Or execute a Java program on your server, capture the results, and display it as a webpage?

      Thanks for the response. I am trying to execute a Java program on a server. As I understand it, I am using a java extension of PHP to accomplish this. Basically I have written a simple java program with a few lines of java code inside the <?php ?> brackets such as $systemInfo = new Java("java.lang.System"); and expect it to run. It is this particular line that calls up the error referred to. (It appears to me that php cannot locate the java jdk ???)

        LOL, well something's going wrong anyway. I don't have a great deal of experience with PHP under Windows, but I'd suggest having a look at the exec() command. For example, this works for me:

        Java program:

        public class javaprog
        {
           public static void main(String[] args)
           {
              System.out.println("Printed by Java program");
              System.exit(8);
           }
        }
        

        PHP code:

        <?
        $output = array();
        $return_var = 0;
        exec("java javaprog", $output, $return_var);
        $output_str = join($output, "\n");
        
        echo "<pre>The output was:\n$output_str\n\n";
        echo "The return value was $return_var</pre>";
        ?>
        

        Obviously you have to compile the Java program first, and if you're running Windows you'll need to use java.exe (I think), and make sure that java.exe is in your path, or give its full location when you call exec().

          Thanks again!! Iwill try again using your code. Where do I locate the java code so that it is automatically compiled and run? According to the "literature" one should be able to place the uncompiled java code directly inside the php code brackets, and run the whole thing. (I think php is having a difficult time locating the java compiler, and the JVM)
          Paul R

            I think you have to compile the Java code yourself first. 🙂 Then place the .class file in the same folder as your PHP file, or another folder that the web server has access to, and give the PHP script the full location of the file.

            As for finding the JVM, I'm not sure...I have something under:

            C:\Program Files\Java\jre1.5.0_06\bin\java.exe

            If that doesn't work, check that you have exec() enabled on your server. Sometimes it's disabled for security reasons.

            I looked up what you were trying to do earlier (generating a Java program dynamically with Php/Java Bridge). I've never used that before, but make sure you've got it installed properly before you try to use it.

              I think you are absolutely right, I have to compile java first and create a .class file! So that solves part of the mystery. I am still unable to use the java predefined library files, and make an instantiation.
              For example: $systemInfo = new Java("java.lang.System"); gave the fatal error of class 'java' not found.
              I will try moving java.dll and java.jar aound to see if I can solve this. I will let you know if I can find the right location.
              Sincerely thanks for the good guidance.
              Paul R

                I tried many locations for java.jar, java.exe, java.dll.
                Also extension_dir, ,extension, java.library.path, java.class.patjh, java.home, java.library,
                classpath, and path.
                PHP still can't find java to parse the statement:
                $systemInfo= new java("java.lang.System");
                I believe that java.lang.System is available in the basic java library already compiled.
                So.... Something seems to be fundamentally wrong, in spite of my weak understanding of what's going on.
                Any other suggestions will be greatly appreciated, as I am sitting here with hundreds of lines of java code that can't be used within PHP.
                Thanks again,
                Paul R

                  Is there any reason why you can't compile the code yourself and just use the .class files? Why do it dynamically?

                    The one and only reason that I was trying to do it dynamically is that every one of the sites and text books describing how to run java with PHP do it that way, and use it as a test to see if the connection between php and java is made.
                    Taking your suggestion, I will try to use a .class file. I will let you know of the outcome.
                    Thanks for your reply.
                    Paul R

                      Dear Pieman86:
                      I used the php and java code that you sent me originally, and IT WORKS!!
                      Amazingly, nowhere that I can find in the books and tutorials on the java/php integration do I find the use of the exec("java javaprog") command. They all indicate that you should use the new Java("javaprog") instructions., which does not work!

                      Thank you so much for getting me going after about a 6 week delay on this.

                        Write a Reply...