سؤال

G' Day,

I have a requirement, where need to invoke java function in PHP script. I have been gone through PHP JAVA Bridge concept but not able to call from PHP script. May be my Process was wrong. Please find the below process what i have been implemented.

  1. step -1 C:\xampp\htdocs\tomcat\webapp Need to pest JavaBridge.war in this webapp.
  2. step - 2 Extract this (JavaBridge.war) file. then go to JavaBridge/WEB-INF/lib/ and copy below three files and pest into C:\xampp\htdocs\tomcat\webapp\bin

    php-script.jar php-servlet.jar servlet_api.jar

  3. Step -3 Edit the Tomcat conf/web.xml. Add the following 9 lines marked with a +:

        + <listener><listener-class>php.java.servlet.ContextLoaderListener</listener-class></listener>
        + <servlet><servlet-name>PhpJavaServlet</servlet-name><servlet-class>php.java.servlet.PhpJavaServlet</servlet-class>
        + </servlet>
        + <servlet><servlet-name>PhpCGIServlet</servlet-name><servlet-class>php.java.servlet.fastcgi.FastCGIServlet</servlet-class>
        + <init-param><param-name>prefer_system_php_exec</param-name><param-value>On</param-value></init-param>
        + <init-param><param-name>php_include_java</param-name><param-value>Off</param-value></init-param>
        + </servlet>
        + <servlet-mapping><servlet-name>PhpJavaServlet</servlet-name><url-pattern>*.phpjavabridge</url-pattern>
    

    + PhpCGIServlet*.php ...

  4. step - 4 Start Tomcat again. Now you can add PHP scripts to tomcat.

  5. step - 5 Add a PHP test file

    <?php require_once("java/Java.inc");
    echo java("java.lang.System")->getProperties(); ?> 
    

    to some web context, for example "examples", and browse to http://yourHost.com:8080/examples/test.php.

Its working fine but when i am run this file in htdocs (http://yourHost.com/test.php) its throwing exceptions.

Please suggest me if i have been implemented wrong process or let me know if any new interface will work through this problem.

I do appreciate for Adv help.

هل كانت مفيدة؟

المحلول

I think you need to set your php.ini to allow url includes. The docs.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top