0

We need to call a user defined java function within php code,so javaBridge connection is needed.

we have done the php-javabridge-configuration and it is working fine. http://phprambabu.blogspot.in/2016/04/php-javabridge-configuration.html

To connect php with java class, we are running the java class from eclipse on tomcat server, HTTP port:8086 and mentioning the same port number in java.inc file, and its path is added in php file as "required_once(Java.inc)".

-> this shows error in Java.inc file but changes made in Java.inc seems correct according to other resources found on internet and stackoverflow.

changes in Java.inc

define ("JAVA_HOSTS", "localhost:8086");

...

if(!defined("JAVA_HOSTS")) {
    if(!java_defineHostFromInitialQuery(java_get_base())) {
        if ($java_ini=get_cfg_var("java.hosts")) define("JAVA_HOSTS",$java_ini);
        else define("JAVA_HOSTS","127.0.0.1:8086");
    }
}

php file content snippet

function createBridge() {
    $demo = new java("main.bridge");
    echo 'New Bridge instance created';
    $demo->fn();
    return $demo;
}

Here, running java src folder contains -> "main" folder contains -> "bridge.java" -> fn() function

if mentioned changes are done in java.inc, Fatal error occurs:

Fatal error: HTTP status 403, Access to the specified resource has been forbidden. Apache Tomcat/7.0.72 in C:\xampp\htdocs\JavaBridge\java\Java.inc on line 869

Line 869 refers to 3rd line of below snippet:

function dieWithBrokenConnection($msg) {
    unset($this->protocol->client->protocol);
    trigger_error ($msg?$msg:"unknown error: please see back end log for details",E_USER_ERROR);
}

And we are using Xampp for local server. Please let us know if I'm doing something wrong in between or any other useful stuff that can help us out.

Soumya Agrawal
  • 159
  • 1
  • 1
  • 8
  • could you also share error message ?? – Ravi Apr 02 '17 at 11:59
  • if mentioned changes are done in java.inc: _Fatal error: HTTP status 403, Access to the specified resource has been forbidden. Apache Tomcat/7.0.72 in C:\xampp\htdocs\JavaBridge\java\Java.inc on line 869 _ Line 869 refers to 3rd line of below snippet: `function dieWithBrokenConnection($msg) { unset($this->protocol->client->protocol); trigger_error ($msg?$msg:"unknown error: please see back end log for details",E_USER_ERROR); }` – Soumya Agrawal Apr 02 '17 at 14:07
  • can you check if `C:\xampp\htdocs\JavaBridge\java\Java.inc` exists ?? Also, make sure filename has same case. – Ravi Apr 02 '17 at 14:17
  • yes i have cross-checked the location, file exists and have same case. – Soumya Agrawal Apr 02 '17 at 14:28
  • which OS are you using ? could you also check the file permission ? – Ravi Apr 02 '17 at 14:29
  • OS is windows 8.1 and all required file permissions are granted i.e. read, write, modify, execute ... and without modifying the Java.inc file, below snippet works correctly. ` ` – Soumya Agrawal Apr 02 '17 at 14:35
  • Ok fine. So, how are you trying to access your java class ? I mean .. have you created jar of it ? – Ravi Apr 02 '17 at 14:40
  • no. I'm running this java project in eclipse as apache tomcat server at port numbers: tomcat admin port:8006, HTTP/1.1: 8086, AJP/1.3: 8010 – Soumya Agrawal Apr 02 '17 at 14:51
  • Sorry, I'm getting. Where is this class written `main.bridge` ? It's in your webapp ? or standalone app ? – Ravi Apr 02 '17 at 14:53
  • yes, class is within webapp project folder i.e. "webAppProject" -> "src"-> "main" package -> bridge.java – Soumya Agrawal Apr 02 '17 at 14:59
  • if you read this post, I think you are doing it wrong http://stackoverflow.com/questions/10204116/how-to-call-custom-java-methods-from-php – Ravi Apr 02 '17 at 15:04
  • We followed the link provided by you and we got stuck as, http://localhost:8080/JavaBridge/ or http://localhost:8086/JavaBridge/ is not working.(we started the tomcat from eclipse itself) . Do we have to import our webAppProject inside "tomcat\webapps" folder explictly? or location of project does not matter? – Soumya Agrawal Apr 02 '17 at 15:57
  • Lets chat http://chat.stackoverflow.com/rooms/139693/trouble-getting-link-to-user-defined-java-class-from-php-using-php-javabridge – Ravi Apr 02 '17 at 16:50
  • I can guide you over chat – Ravi Apr 02 '17 at 16:51
  • i don't have enough reputations to chat on stackoverflow... any other alternative? – Soumya Agrawal Apr 02 '17 at 16:55
  • Let me see, if I can do anything – Ravi Apr 02 '17 at 16:58
  • Could you check now ? – Ravi Apr 02 '17 at 17:00
  • no still not able to chat over that link. – Soumya Agrawal Apr 02 '17 at 17:05
  • thing is , it is very difficult to talk/understand over comment. – Ravi Apr 02 '17 at 17:10
  • It seems like you have two web server . You need to deploy webAppProject explicitly. Then, try accessing it localhost:port/webAppProject – Ravi Apr 02 '17 at 17:13
  • i understand that, can this be possible over any other resources like gmail or anything? we are using xampp and path of the project is not accessible i.e. localhost:port/webAppProject is not running – Soumya Agrawal Apr 02 '17 at 17:24
  • Deleted my previous comment. I hope.. you would have copied my email id. – Ravi Apr 02 '17 at 17:30
  • Just in case, I've set up some doc for tomcat installation http://docs.soluble.io/soluble-japha/install_server/#quick-install. They are based on a javabridge fork https://github.com/belgattitude/php-java-bridge, you'll find some tips that I hope could help – Sébastien Vanvelthem Apr 03 '17 at 08:51

0 Answers0