[Reprint] phpjava interaction php/javabridge

Source: Internet
Author: User
[Reprint] phpjava interaction phpjavabridge 1. Install java jdk and tomcat

2. install apache and php
3. download php-java-bridge_5.5.4_documentation.zip
4_decompress php-java-bridge_5.5.4_documentation.zip
5. copy JavaBridge. war under the root directory after decompression to the webapp Directory of the tomcat server.
6. start the tomcat server
7. to use java in php, you only need to add the following line of statements:


Yes:

$ Date = new Java ('Java. util. date ');
Echo $ date-> getDate ();
?>
Run successfully, OK!

Call your own class, first package it into a jar file, and write: jar cf Test. jar Test. java during running. Put the tomcat release directory WEB-INF/lib.
Test. java is as follows:
Public class Test {
Public String rsStr;
Public static void main (String [] args)
{
System. out. println ("Hello World! ");
}
Public void setString (String param ){
If (param. equals ("")){
RsStr = "Hello, how are you! ";
} Else {
RsStr = param;
}
}

Public String getString (){
Return rsStr;
}
}


The PHP file called is as follows:
$ T = new java ("Test ");
Echo get_class ($ t );
$ T-> setString ("ffffffffffff ");
Echo $ t-> getString ();
// Echo "ddjsa; fjsjf; sja; fl ";
$ T-> setString ("dddddddddddddddd ");
Echo $ t-> getString ();
$ T-> setString ("33333333333333333333 ");
Echo $ t-> getString ();
// ******************************** My jar
$ T1 = new java ("IndexTest ");
Print ($ t1-> searchWord ("city", "Shanghai", "E: \ workspace \ tuan800 "));
?>

Call the jar file function of jar: export of eclipse that contains import in the custom class, and select the project of the class to be packaged. Package it and put it under the tomcat release directory of the WEB-INF/lib.
But lucene into version 3.0.0, packaging only class, lucene core package directly copy to tomcat release directory of the WEB-INF/lib.
Normal call.
Jar package
Http://repo1.maven.org/maven2/org/apache/lucene/lucene-core/3.0.0/
Search class:
Http://apps.hi.baidu.com/share/detail/5600609

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.