lajp 实现php高效率调用java

WBOY
Release: 2016-06-13 12:28:00
Original
1237 people have browsed it

lajp 实现php高效调用java
http://blog.chinaunix.net/uid-20767210-id-1849682.html

轻量级框架,非常好用,且线程交互,非常高效,在复杂的项目都可以寅刃尔解.

具体实现过程:

1.下载lajp的包,地址http://code.google.com/p/lajp/,解压缩,然后修改make.sh文件,把里面的java_home修改过后,make过后,把里面的so文件copy到java的库(java.library.path)文件任意目录下面。
2.然后到java的目录下启动run_msgq.sh,
  注意如果用到了第三方包的话一定要在此处的classpath里面引用,相对路径也可以。用命令nohup ./run.sh & 后台启动

3.在/var/www/html/health/下面新建一个testphpjava.php,内容如下:

require_once("php_java.php");  //引用下载的php_java.php文件

$name = "Ali";

try
{
  //调用Java的hello.HelloClass类中的hello方法
  $ret = lajp_call("hello.HelloClass::hello", $name);
  echo "{$ret}
";
}
catch (Exception $e)
{
  echo "Err:{$ret}
";
}
?>
4.在浏览器里输入http://localhost/health/testphpjava.php
你会看到HelloWorld,这是java返回的字符串。

5.自己可以写一个新的类进行测试,但是一定要放在lajp下的java目录下,调用方式用lajp_call();,如果用到非常复杂的类,那么在php和java中一定要有对应的类,具体请参考网站文档。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template