Table of Contents
本项目需要软件:" >本项目需要软件:
1.配置PHP+MySql+Apache
1.1使用安装包进行安装
1.2测试php环境
1.3 IDE
2配置Java环境
2.1安装jdk
2.2测试
3使用JavaBridge
3.1软件需求
3.2运行JavaBridge
3.3测试JavaBridge
3.4在PHP中调用自己创建的JAVA 类
4 SVN
Home php教程 php手册 PHP+JavaBridge完整环境配置

PHP+JavaBridge完整环境配置

Jun 22, 2016 pm 08:00 PM
java php code Open source Environment configuration programming programming language software development

 

环境:64位win7操作系统

本项目需要软件:

Xampp(xampp-win32-1.8.1-VC9-installer)安装包:http://www.apachefriends.org/zh_cn/xampp-windows.html#1787

EclipsePHP Studio3http://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 是最简单的方法。

image

XAMPP win32 的安装向导
安装过程结束后,您会在 开始/程序/XAMPP 菜单下找到 XAMPP。您可以使用 XAMPP 控制面板来启动/停止所有服务或安装/卸载所有服务。

image

XAMPP 控制面板能启动/停止 Apache、MySQL、FilaZilla 和 Mercury,或直接将其安装为服务

1.2测试php环境

编写helloworld.php并放入xampp安装目录下的htdocs文件夹

在浏览器端输入http://localhost/helloworld.php。并得到以下输出,则表示正确。

image

1.3 IDE

安装EclipsePHP Studio3,并将工作空间指向XAMPP目录下的htdocs,启动xampp,这样编写的php文件就直接保存在htdocs文件夹内,可以直接调试。

image

 

image

2配置Java环境

2.1安装jdk

得到JDK的安装文件,点击安装,如图所示:

image

 

 

· 安装成功后,假设安装路径为C:\Program Files\Java\jdk1.7.0_05,右键点击我的电脑选择Properties,得到界面如图:

image

 

· 点击Advanced system settings,得到界面如图:

image

 

· 点击Environment Variables…得到界面如图:

image

 

 

· 在System variables中找到Path并双击进行编辑,得到界面如图:

image

 

 

· 在Variable value的末尾加上“;”和JDK和Jre的bin文件夹,即“;C:\Program Files\Java\jre7\bin;C:\Program Files\Java\jdk1.7.0_05\bin”,点击OK即可,如图:

image

2.2测试

在键盘上键入WINDOWS+R,并在open栏中输入cmd,回车,进入命令行。键入java -version并按Enter键,若得到界面如下图所示,即JDK环境配置成功。

image

3使用JavaBridge

3.1软件需求

Ø php-java-bridge_6.2.1_documentation.ziphttp://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同一个目录)替代双击。弹出对话框后不用选择,直接点击“确定”即可。正确如下:

image

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使用帮助文档。

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
The Compatibility of IIS and PHP: A Deep Dive The Compatibility of IIS and PHP: A Deep Dive Apr 22, 2025 am 12:01 AM

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.

What happens if session_start() is called multiple times? What happens if session_start() is called multiple times? Apr 25, 2025 am 12:06 AM

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  : Adaptations and Innovations The Future of C : Adaptations and Innovations Apr 27, 2025 am 12:25 AM

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  : Is It Dying or Simply Evolving? C : Is It Dying or Simply Evolving? Apr 24, 2025 am 12:13 AM

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

Composer: Aiding PHP Development Through AI Composer: Aiding PHP Development Through AI Apr 29, 2025 am 12:27 AM

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.

What does 'platform independence' mean in the context of Java? What does 'platform independence' mean in the context of Java? Apr 23, 2025 am 12:05 AM

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.

What is the significance of the session_start() function? What is the significance of the session_start() function? May 03, 2025 am 12:18 AM

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

Behind the Scenes: What Language Powers JavaScript? Behind the Scenes: What Language Powers JavaScript? Apr 28, 2025 am 12:01 AM

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.

See all articles