PHP and Java: Powerful Forces Combined
by Leonard Anghel
A long time ago, somebody from the WWW planet saw a bright spot on the sky and decided to name it Java. Around the same time, but in a different location, another dreamer saw another bright spot and named it PHP.
As days passed, the spots grew brighter and brighter, until one day they began to shake, creating the impression that they wanted to move. Shortly thereafter, Java and PHP took flight, two huge comets flying at high speeds through the programming sky. As the two languages got stronger, they became highly appreciated by dedicated developers, who began to ask: What would happen if these two titans ever met? Could we combine their powers constructively?
Trying to answer these questions gave birth to the PHP/Java Bridge, that creates a communication channel between these two entities. Using the bridge, you can develop classes in Java and call their methods from PHP or you can use PHP scripts in your Java desktop/web applications.
In this article, you'll learn how to:
- Install and configure the PHP/Java Bridge
- Use Java classes in PHP scripts
- Use PHP scripts in Java classes
- Use PHP scripts in JSP pages
- Use PHP scripts in Java desktop applications
- Run PHP scripts using the jrunscript tool
Let's get started!
Install and Configure PHP/Java Bridge
The current distribution of the PHP/Java Bridge is available in .zip here. The installation process depends which Java platform will be interacting with PHP through this bridge.
For J2SE, installation is simple:
Here's how to install the PHP/Java Bridge for J2EE:
- Copy
JavaBridge.war archive into the auto-deploy folder of your J2EE server or servlet engine (Tomcat, Resin, etc.)
- Rename this
.war archive whatever you're calling the new application and restart the J2EE server. Wait for the auto-deploying process to create the directory associated to this .war. In this example, the app is called appName.war.
- Test the new application from the browser like this:
http://localhost:8080/appName (click on test.php).
- If you have your J2EE server running on a different host or listen on a different port, then modify these parameters accordingly.
Author's Note: If you want to run J2EE/PHP applications from Apache or IIS, copy the directory that contains appName over to the Apache/IIS document root. |
New on the Java Boutique:
New Review:
Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling
API boasts simplicity, ease-of-integration, a well-rounded feature
set, and it's free!
New Applet:
Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA
sequences into three useful formats.
Elsewhere on internet.com:
WebDeveloper Java
Lots of Java information on webdeveloper.com
WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.
ScriptSearch Java
Hundreds of free Java code files to download.
jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.