PHP hello world module (jar version)
From Resin 3.0
m (PHP Hello World (Java Version) moved to PHP Hello World Java Module) |
|||
Line 26: | Line 26: | ||
Copy the following file into your favorite text editor (notepad will do) and save it to the c:\sandbox\src\example directory. | Copy the following file into your favorite text editor (notepad will do) and save it to the c:\sandbox\src\example directory. | ||
− | ==== | + | ====HelloModule.java==== |
package example; | package example; | ||
import com.caucho.quercus.module.AbstractQuercusModule; | import com.caucho.quercus.module.AbstractQuercusModule; | ||
− | public class | + | public class HelloModule extends AbstractQuercusModule { |
− | public String | + | public String hello_test(String name) |
{ | { | ||
return "Hello, " + name; | return "Hello, " + name; |
Revision as of 23:38, 5 December 2005
Contents |
Introduction
One of the advantages of using Resin's implementation of PHP is that you can create your own library of functions written in Java and access them from within PHP. The following article provides a brief tutorial on how to do this.
The article assumes that you have already properly installed Resin on your computer. Please see the related article PHP Hello World for more information on installing Resin for the first time.
Step 1: Create Example.jar and place it in the appropriate directory
Create your development environment
The steps that follow assume you are working in a Windows environment. If you are working within Unix (or Linux or Mac), the same steps will work. Just be sure to modify the commands where necessary.
c:\Documents and Settings\Charles >cd c:\ c:\> md sandbox c:\sandbox> md src c:\sandbox> md classes c:\sandbox> cd src c:\sandbox\src> md example c:\sandbox\src> md META-INF c:\sandbox\src> cd META-INF c:\sandbox\src\META-INF> md services
Create HelloWorldSampleClass.java
Copy the following file into your favorite text editor (notepad will do) and save it to the c:\sandbox\src\example directory.
HelloModule.java
package example; import com.caucho.quercus.module.AbstractQuercusModule; public class HelloModule extends AbstractQuercusModule { public String hello_test(String name) { return "Hello, " + name; } }
Create com.caucho.quercus.QuercusModule
Copy the following one line file and save it to the c:\sandbox\src\META-INF\services directory. Make sure that the file name is exactly "com.caucho.php.PhpModule"
com.caucho.quercus.QuercusModule
example.HelloWorldSampleClass
Compile and Jar the files
Navigate to c:\sandbox
C:\sandbox>javac -d classes -classpath c:\resin-3.0.13\lib\quercus.jar src\example\*.java
Note: In my installation of Resin, the file httpd.exe is located in c:\resin-3.0.13. If you have installed Resin in a different directory change the above classpath appropriately.
Copy Example.jar to your working resin directory
Step 2: Create and browse the PHP page
javahello.php
<?php $name = say_hello("Charles"); echo $name; ?>
Conclusion
Enjoy