[Reprint] php Java interactive Php/java Bridge

Source: Internet
Author: User
1. To install the Java JDK, install Tomcat

2, install the good apache,php
3. Download Php-java-bridge_5.5.4_documentation.zip
4, decompression Php-java-bridge_5.5.4_documentation.zip
5. Copy the Javabridge.war to the WebApp directory of the Tomcat server under the extracted root directory.
6. Start the Tomcat server
7. To use Java in PHP simply add the following line of statements:


OK:

$date =new Java (' java.util.Date ');
echo $date->getdate ();
?>
Run through, ok!

Call your own class, first packaged into a jar file, run in write: Jar CF Test.jar Test.java. Put it under the Tomcat publishing directory Web-inf/lib.
Test.java 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 is you!";
}else{
Rsstr = param;
}
}

Public String getString () {
return rsstr;
}
}


The PHP file is called 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
$t 1 = new Java ("Indextest");
Print ($t 1->searchword ("City", "Shanghai", "e:\\workspace\\tuan800"));
?>

Invoke the Jar file feature in the custom class that contains the import's export to package jar:eclipse, and select the project where the class you want to package is located. After packaging, place it under the web-inf/lib of the Tomcat publishing directory.
But when Lucene was replaced by 3.0.0, the package was only used to hit the class, and Lucene's core package was copied directly to the web-inf/lib of the Tomcat publishing directory.
Normal call.
Jar Package
http://repo1.maven.org/maven2/org/apache/lucene/lucene-core/3.0.0/
Search for 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.