With the help of the board here I've managaged to get all of the examples working.

Now I need to figure out how to get my own objects working. Each time i try to instantiate one of my java classes, I get a java.lang.ClassNotFoundException.

Here is my setup:
I placed my class files into c:\php4\extensions and then added this to the library path:

[java]
extension=php_java.dll
java.class.path="c:\php4\php_java.jar"
java.home="C:\program files\JavaSoft\JRE\1.3"
java.library.path="c:\php4\;c:\php4\extensions\"
java.library="C:\program files\JavaSoft\JRE\1.3\bin\hotspot\jvm.dll"

Have I set the wrong variable?

    Your php_java.dll and php_java.jar have to be in the same directory. Don't ask me why, but they do.

      yeah, I figured that out through trail and error. I was most frustrated when I read a mailing list article about the Java implementation. The email from one of the developers said "Yes, I should write some documentation, but there is all of this fun code to write". Zend.com should have stepped in by now.

      Anyway, I've tried some more permutation of where to place my own class files, and have had no luck.

        re: own class files

        I haven't had any luck with using Java class files either. I think they don't work in PHP.

          2 months later

          Jason@hspace.net wrote:

          Your php_java.dll and php_java.jar have to be in the same directory. Don't ask >me why, but they do.

          I don't believe so. The entry listed under extension (php_java.dll) is searched for in the entry that's specified by extension_dir. This directory should also be listed in java.library.path. The java.class.path entry is what's used as the CLASSPATH setting for the JVM so it must contain all the directories and JARs that include Java classes you want to be visible to the JVM (including php_java.jar and the directories that contain your own individual class files). Separate the values for any of these ini keys just as you would any PATH specification.

          Let me know if you're still having problems.

          Alex

            You should add c:\php4\extensions to java.class.path instead of java.library.path. The java.library.path specifies where to search for libraries (i.e. DLL files) such as jvm.dll, php_java.dll, etc. If your java.library.path includes all the necessary jvm directories then your java.library entry should simply be jvm.dll.

            You should also make sure that extension_dir is set to the directory that contains php_java.dll prior to the line extension=php_java.dll.

            Let me know if you're still having problems.

            Alex

              14 days later

              I am seeing the same phenomenon on Linux (RH 7.0) and Blackdown JDK 118.

              The examples all work fine. But attempting to construct a simple Hello php world ($hello = new Java("hello")😉, results in a ClassNotFoundException, when the class is both in the environment classpath, and the php classpath setting (which are identical). I haven't futzed with java.library.path because the README says that is only applicable to Java 2+.

                Aaron,

                What does your Java class do? A simple test to try is to write another Java class that references your Java class in the same way you want your php code to reference it. If the Java code can see the class then things should be cool for php. However, if php is the only one that has a problem then there might be something wrong with php's Java support or your php setup.

                Alex

                  14 days later
                  a year later

                  Even with all of you guys helping it took a while to figure out what was wrong, but basically the problem is that in the php.ini file the java.class.path line should be adjusted to reflect the location of both your php_java.jar file and the .class file directory that you want to use. In my case this class path line is:

                  java.class.path = "c:\PHP\java\php_java.jar;c:\PHP\java\"

                  Please note the quotes around the line (if you don't use the quotes the last directory will be interpreted as a comment)

                  Good Luck!

                  Regards,
                  Ferry

                    Write a Reply...