PHP+JavaBridge完整环境配置
环境:64位win7操作系统
本项目需要软件:
Xampp(xampp-win32-1.8.1-VC9-installer)安装包:http://www.apachefriends.org/zh_cn/xampp-windows.html#1787
EclipsePHP Studio3:http://epp.php100.com/#down
Php java-bridge(php-java-bridge_6.2.1_documentation.zip): http://php-java-bridge.sourceforge.net/pjb/download.php
JDK( 我们使用的版本为:Java(TM)Plaform SE 7 U5即jdk-7u5-windows-x64.exe):在oracle官网可下
1.配置PHP+MySql+Apache
许多人通过他们自己的经验认识到安装 Apache 服务器是件不容易的事儿。如果您想添加 MySQL、PHP 和 Perl,那就更难了。
XAMPP 是一个易于安装且包含 MySQL、PHP 和 Perl 的 Apache 发行版。XAMPP 的确非常容易安装和使用:只需下载,解压缩,启动即可。
1.1使用安装包进行安装
使用安装包来安装 XAMPP 是最简单的方法。
XAMPP win32 的安装向导
安装过程结束后,您会在 开始/程序/XAMPP 菜单下找到 XAMPP。您可以使用 XAMPP 控制面板来启动/停止所有服务或安装/卸载所有服务。
XAMPP 控制面板能启动/停止 Apache、MySQL、FilaZilla 和 Mercury,或直接将其安装为服务
1.2测试php环境
编写helloworld.php并放入xampp安装目录下的htdocs文件夹
在浏览器端输入http://localhost/helloworld.php。并得到以下输出,则表示正确。
1.3 IDE
安装EclipsePHP Studio3,并将工作空间指向XAMPP目录下的htdocs,启动xampp,这样编写的php文件就直接保存在htdocs文件夹内,可以直接调试。
2配置Java环境
2.1安装jdk
得到JDK的安装文件,点击安装,如图所示:
· 安装成功后,假设安装路径为C:\Program Files\Java\jdk1.7.0_05,右键点击我的电脑选择Properties,得到界面如图:
· 点击Advanced system settings,得到界面如图:
· 点击Environment Variables…得到界面如图:
· 在System variables中找到Path并双击进行编辑,得到界面如图:
· 在Variable value的末尾加上“;”和JDK和Jre的bin文件夹,即“;C:\Program Files\Java\jre7\bin;C:\Program Files\Java\jdk1.7.0_05\bin”,点击OK即可,如图:
2.2测试
在键盘上键入WINDOWS+R,并在open栏中输入cmd,回车,进入命令行。键入java -version并按Enter键,若得到界面如下图所示,即JDK环境配置成功。
3使用JavaBridge
3.1软件需求
Ø php-java-bridge_6.2.1_documentation.zip: http://php-java-bridge.sourceforge.net。
Ø JavaBridge.jar:将上面的php-java-bridge_6.2.1_documentation.zip解压得到一个JavaBridge.war,将JavaBridge.war重命名为JavaBridge.jar,再次用WinRAR对JavaBridge.jar解压到JavaBridge目录,在JavaBridge\WEB-INF\LIB里面可以找到JavaBridge.jar。
Ø Lucene.jar:将上面的php-java-bridge_6.2.1_documentation.zip解压得到一个JavaBridge.war,将JavaBridge.war重命名为JavaBridge.jar,再次用WinRAR对JavaBridge.jar解压到JavaBridge目录,在JavaBridge\WEB-INF\LIB里面可以找到Lucene.jar。
Ø JDK:JavaBridge是由Java语言实现的,所以必须安装JDK实现对jar文件执行提供支持。
3.2运行JavaBridge
双击运行JavaBridge.jar,应该会弹出一个可以选择的对话框,如果没有弹出,是因为没有安装JDK或者文件关联错误,解决方法是安装JDK或者运行“start javaw -jar JavaBridge.jar”(内容保存到*.bat里面,而*.bat与JavaBridge.jar同一个目录)替代双击。弹出对话框后不用选择,直接点击“确定”即可。正确如下:
3.3测试JavaBridge
新建一个test.php(*.php xampp安装目录下的htdocs文件夹)文件,内容如下:
require_once("java/Java.inc");
// get instance of Java class java.lang.System in PHP
$system = new Java('java.lang.System');
$s = new Java("java.lang.String", "php-java-bridge config...
");
echo $s;
// demonstrate property access
print 'Java version='.$system->getProperty('java.version').'
';
print 'Java vendor=' .$system->getProperty('java.vendor').'
';
print 'OS='.$system->getProperty('os.name').' '.
$system->getProperty('os.version').' on '.
$system->getProperty('os.arch').'
';
// java.util.Date example
$formatter = new Java('java.text.SimpleDateFormat',
"EEEE, MMMM dd, yyyy 'at' h:mm:ss a zzzz");
print $formatter->format(new Java('java.util.Date'));
?>
Java.inc应该放到java目录下,而java应该与test.php同目录,解压JavaBridge.jar可以在JavaBridge\META-INF里面找到java目录,完全拷贝java目录与test.php同目录。执行test.php得到如下输出或类似输出则表现正确:
3.4在PHP中调用自己创建的JAVA 类
非开发人员可以略过本节。
得到上面输出说明JavaBridge安装成功了,PHP可能调用JAVA内部的类,下面使用Java编写自己的类,而PHP则调用自己写的Java类。
为了尽排除错误,先建立一个EchoHello.java进行测试,代码如下:
public class EchoHello
{
public String test()
{
return "conguratulation php can call methods from java";
}
}
在Eclipse中执行一次EchoHello.java,会在工程目录下的BIN目录下生成EchoHello.class文件,将EchoHello.class拷贝到C:\Program Files\Java\jre7\classes目录下,因为版本号的不同,jre7文件夹名字可能不同。安装JDK时候默认没有C:\Program Files\Java\jre7\classes,需要手动建立。
测试自己的JAVA类,修改test.php代码如下:
include_once("java/java.inc");
$eh = new Java("EchoHello");
echo $eh->test();
?>
需要重新启动JavaBridge.jar再运行test.php方法是:到任务管理器里面结束java.exe和javaw.exe,重新双击运行javaBridge.jar,不用选择下列列表,直接“确定”即可。
运行test.php得到"conguratulation php can call methods from java"的输出可以进行下一步,否则重复上面的步骤。
4 SVN
TortoiseSVN 64位的1.7.10:http://tortoisesvn.net/downloads.zh.html
同时下载汉语言包进行安装。
在http://tortoisesvn.net/support.zh.html svn使用帮助文档。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

Multiple calls to session_start() will result in warning messages and possible data overwrites. 1) PHP will issue a warning, prompting that the session has been started. 2) It may cause unexpected overwriting of session data. 3) Use session_status() to check the session status to avoid repeated calls.

The future of C will focus on parallel computing, security, modularization and AI/machine learning: 1) Parallel computing will be enhanced through features such as coroutines; 2) Security will be improved through stricter type checking and memory management mechanisms; 3) Modulation will simplify code organization and compilation; 4) AI and machine learning will prompt C to adapt to new needs, such as numerical computing and GPU programming support.

C isnotdying;it'sevolving.1)C remainsrelevantduetoitsversatilityandefficiencyinperformance-criticalapplications.2)Thelanguageiscontinuouslyupdated,withC 20introducingfeatureslikemodulesandcoroutinestoimproveusabilityandperformance.3)Despitechallen

AI can help optimize the use of Composer. Specific methods include: 1. Dependency management optimization: AI analyzes dependencies, recommends the best version combination, and reduces conflicts. 2. Automated code generation: AI generates composer.json files that conform to best practices. 3. Improve code quality: AI detects potential problems, provides optimization suggestions, and improves code quality. These methods are implemented through machine learning and natural language processing technologies to help developers improve efficiency and code quality.

Java's platform independence means that the code written can run on any platform with JVM installed without modification. 1) Java source code is compiled into bytecode, 2) Bytecode is interpreted and executed by the JVM, 3) The JVM provides memory management and garbage collection functions to ensure that the program runs on different operating systems.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.
