How to Import PHP Java

How to Import PHP Java thumbnail
PHP and Java technologies are intertwined in PHP/Java Bridge.

The PHP/Java Bridge application merges Java and PHP together into a single dynamic tool. In this application, PHP handles the front end while Java takes charge of the back end. PHP will invoke Java procedures/functions using HTTP and/or XML technologies. Since the PHP/Java Bridge integrates these two dynamic web tools with one another, importing any file created with this application is not too difficult if you have some programming experience.

Instructions

    • 1

      Download the PHP/Java Bridge application from the SourceForge website (see Resources). This will let you obtain a JEE standard web application called JavaBridge.war. The compressed file contains sample PHP scripts, the JavaBridge.jar Java library, and a MIT-licensed PHP Java class, which is another option to include to your PHP scripts. Extract the zipped file and install it on your web server.

    • 2

      Input the following code to start the PhpJavaServlet that handles your PHP clients' requests. This action will trigger the PhpJavaServlet to access a local back-end while it listens for PHP/Java Bridge protocol requests and it eventually invokes Java functions or procedures.

      <?php

      require_once("http://localhost:8080/JavaBridge/java/Java.inc");

      $System = java("java.lang.System");

      echo $System->getProperties();

      ?>

      The process will look like this:

      Apache/IIS/console::PHP <--> PhpJavaServlet

    • 3

      Use the following code as an alternative, if you want to direct the PHP front end to a specific HTTP back end. This setup needs an HTTP server that is PHP-enabled, such as Apache or IIS, or a console PHP executable as the front-end.

      <?php

      define ("JAVA_HOSTS", "ssl://mySecureHost.com:8443");

      define ("JAVA_SERVLET", "/JavaBridge/servlet.phpjavabridge");

      require_once("Java.inc");

      $System = java("java.lang.System");

      echo $System->getProperties();

      ?>

    • 4

      Run the following code to integrate and auto-load handler to import Java into the PHP's environment. This process auto-loads the standard Java classes and makes them available for PHP to distribute to any browser that supports JavaScript.

      <?php

      require_once("http://localhost:8080/JavaBridge/java/Java.inc");

      use java\lang\String as JString;

      use java\util\ArrayList as JList;

      class String extends JString {

      function toString () {

      return "hello " . parent::toString();

      }

      }

      $str = new String("Java");

      $list = new JList();

      $list->add (java_closure($str));

      $list->add ("from PHP");

      $ar = java_values ($list->toArray());

      foreach($ar as $entry) echo "$entry\n"

      ?>

      =>hello Java

      from PHP

Tips & Warnings

  • Several free online tutorials are available about PHP and Java integration. Use as many as you can to become more familiar with this advanced technology. You can also join discussion groups to seek advice from experienced JAVA and PHP developers.

Related Searches:

References

Resources

  • Photo Credit Jupiterimages/Photos.com/Getty Images

Comments

Related Ads

Featured