How to call custom java methods from PHP?

放肆的年华 提交于 2019-11-29 12:07:29
Milind

First of all install Tomcat6 and Java in you Unix box. Most probably your Tomcat will be on 8080 port. Now Download JavaBridge.war from http://php-java-bridge.sourceforge.net/pjb/ unzip it. Then from WEB-INF/lib folder copy JavaBridge.jar ,php-servlet.jar and php-script.jar in lib folder of Tomcat. Then copy JavaBridge.war in your Tomcat6 webapps folder and restart your tomcat6 service which will deploy automatically JavaBridge folder in your webapps

Now try to browse http://localhost:8080/JavaBridge/. If you get working than your PHP/Java Bridge installed. First Part is over.

Now make test page in your apache as below

<?php
      require_once("http://localhost:8080/JavaBridge/java/Java.inc");
      echo java("java.lang.System")->getProperties();
?>

and run it. If it works then you can start working with your work. If it not work then you have problem with you php.ini file. Try to make allow_url_once=on in your php.ini.

Now just copy your java jar file in tomcat /webapps/JavaBridge/WEB-INF/lib/ folder and Just always put following line in your page where ever you want java to work

require_once("http://localhost:8080/JavaBridge/java/Java.inc");
$yourObj = Javav("your java class");
$yourObj->yourMethod();
$yourObj->setProperty("xxx");

Hope this can help you out.

IF you have still any problem get back.

Yea it will throw error because you must not have copied your java compiled file may be your jar file in PHP / Java Bridge.

You can to do in following 2 options way

  1. If you have define your CATALINA_HOME then copy $CATALINA_HOME/webapps/JavaBridge/WEB-INF/lib
  2. If you have not define your CATALINA_HOME then copy /var/lib/tomcat6/webapps/webapps/JavaBridge/WEB-INF/lib

Path which I am telling it assumes that you have install tomcat6, may be your tomcat webapps folder may be in different path.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!