From: <php...@li...> - 2006-10-14 15:26:05
|
Hi, [please excuse the delay] > The title of the email says it all! I know PHP like > the back of my > hand, but know little to nothing about Java. you don't need java knowledge to invoke methods from Java libraries. In fact you don't even need Java to call out to Java libraries, if you have a recent version of gcc installed (Linux only). > 1) What are the standard "include" files I need at > the top of each of > my PHP scripts to utilize the Bridge? require_once("java/Java.php") is enough. > 2) How do I gain access to certain Java methods in > my PHP scripts? with require_once("java/Java.php"); java_require("/path/to/myLib.jar;...); $myClass = new Java("myLib.myClass"); ... > For example if I want to convert a string read from > a file into an > array of values I think I would use > $array_var->toCharArray > ($string_var). I believe I need the > "java.lang.string" library/class > thing (found this in the Java API docs at Sun.com) > but I cannot > figure out how to enable this class or method in my > PHP scripts? The low-level interface is: require_once("java/Java.php"); $string = new java("java.lang.String", "hello"); $ar = java_values($string->toCharArray()); The high-level interface: require_once("java/java_lang_String"); $string = new java_lang_String("hello"); $ar = java_values($string->toCharArray()); > errors). So how do I call or access the classes in > that file? For > example, there is a class called "Utility" which in > turn has a method > called "read") in the JAR file. I tried the > following: > > <?php > java_require("/Library/WebServer/Documents/cj/simapi-java-5.0.0/lib/ > > cybsclients15.jar"); > $handle = new Java("Utility"); > $props = $handle->read("config.properties"); > ?> You must use the full qualified name. For example: $handle = new Java("com.foo.something.Utility"); You can see the name by opening the .jar file with winzip for example. Regards, Jost Boekemeier ___________________________________________________________ Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de |