PHP hello world module (jar version)

From Resin 3.0

(Difference between revisions)
Jump to: navigation, search
Line 23: Line 23:
 
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.
  
 +
====HelloWorldSampleClass.java====
 
  package Example;<br/>
 
  package Example;<br/>
 
  import com.caucho.php.module.AbstractPhpModule;
 
  import com.caucho.php.module.AbstractPhpModule;
Line 32: Line 33:
 
   }
 
   }
 
  }
 
  }
====HelloWorldSampleClass.java====
 
  
 
===Create com.caucho.php.PhpModule ===
 
===Create com.caucho.php.PhpModule ===
Line 38: Line 38:
 
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"
 
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"
  
Example.HelloWorldSampleClass
 
 
====com.caucho.php.PhpModule====
 
====com.caucho.php.PhpModule====
 +
Example.HelloWorldSampleClass
 +
  
===Jar the files===
+
===Compile and Jar the files===
  
 
==Step 2: Create the PHP page==
 
==Step 2: Create the PHP page==

Revision as of 17:39, 5 December 2005


Contents

Introduction

This short article is intended for java programers who are interested in creating there own libraries which can be invoked from within a PHP page. It assumes that Resin's PHP implementation is installed and working correctly 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

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> 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.

HelloWorldSampleClass.java

package Example;
import com.caucho.php.module.AbstractPhpModule; import com.caucho.php.env.StringValue;
public class HelloWorldSampleClass extends AbstractPhpModule {
public StringValue say_hello(String name) { return new StringValue("Hello, " + name); } }

Create com.caucho.php.PhpModule

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.php.PhpModule

Example.HelloWorldSampleClass


Compile and Jar the files

Step 2: Create the PHP page

javahello.php

?php
$name = say_hello("Charles"); echo $name;
?>

Conclusion

Enjoy

Personal tools