PHP+JavaBridge完整環(huán)境配置
Jun 22, 2016 pm 08:00 PM?
環(huán)境:64位win7操作系統(tǒng)
本項目需要軟件:
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官網(wǎng)可下
1.配置PHP+MySql+Apache
許多人通過他們自己的經(jīng)驗認識到安裝 Apache 服務(wù)器是件不容易的事兒。如果您想添加 MySQL、PHP 和 Perl,那就更難了。
XAMPP 是一個易于安裝且包含 MySQL、PHP 和 Perl 的 Apache 發(fā)行版。XAMPP 的確非常容易安裝和使用:只需下載,解壓縮,啟動即可。
1.1使用安裝包進行安裝
使用安裝包來安裝 XAMPP 是最簡單的方法。
XAMPP win32 的安裝向?qū)?
安裝過程結(jié)束后,您會在 開始/程序/XAMPP 菜單下找到 XAMPP。您可以使用 XAMPP 控制面板來啟動/停止所有服務(wù)或安裝/卸載所有服務(wù)。
XAMPP 控制面板能啟動/停止 Apache、MySQL、FilaZilla 和 Mercury,或直接將其安裝為服務(wù)
1.2測試php環(huán)境
編寫helloworld.php并放入xampp安裝目錄下的htdocs文件夾
在瀏覽器端輸入http://localhost/helloworld.php。并得到以下輸出,則表示正確。
1.3 IDE
安裝EclipsePHP Studio3,并將工作空間指向XAMPP目錄下的htdocs,啟動xampp,這樣編寫的php文件就直接保存在htdocs文件夾內(nèi),可以直接調(diào)試。
?
2配置Java環(huán)境
2.1安裝jdk
得到JDK的安裝文件,點擊安裝,如圖所示:
?
?
· 安裝成功后,假設(shè)安裝路徑為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環(huán)境配置成功。
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語言實現(xiàn)的,所以必須安裝JDK實現(xiàn)對jar文件執(zhí)行提供支持。
3.2運行JavaBridge
雙擊運行JavaBridge.jar,應(yīng)該會彈出一個可以選擇的對話框,如果沒有彈出,是因為沒有安裝JDK或者文件關(guān)聯(lián)錯誤,解決方法是安裝JDK或者運行“start javaw -jar JavaBridge.jar”(內(nèi)容保存到*.bat里面,而*.bat與JavaBridge.jar同一個目錄)替代雙擊。彈出對話框后不用選擇,直接點擊“確定”即可。正確如下:
3.3測試JavaBridge
新建一個test.php(*.php xampp安裝目錄下的htdocs文件夾)文件,內(nèi)容如下:
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應(yīng)該放到j(luò)ava目錄下,而java應(yīng)該與test.php同目錄,解壓JavaBridge.jar可以在JavaBridge\META-INF里面找到j(luò)ava目錄,完全拷貝java目錄與test.php同目錄。執(zhí)行test.php得到如下輸出或類似輸出則表現(xiàn)正確:
3.4在PHP中調(diào)用自己創(chuàng)建的JAVA 類
非開發(fā)人員可以略過本節(jié)。
得到上面輸出說明JavaBridge安裝成功了,PHP可能調(diào)用JAVA內(nèi)部的類,下面使用Java編寫自己的類,而PHP則調(diào)用自己寫的Java類。
為了盡排除錯誤,先建立一個EchoHello.java進行測試,代碼如下:
public class EchoHello
{
public String test()
{
return "conguratulation php can call methods from java";
}
}
在Eclipse中執(zhí)行一次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方法是:到任務(wù)管理器里面結(jié)束java.exe和javaw.exe,重新雙擊運行javaBridge.jar,不用選擇下列列表,直接“確定”即可。
運行test.php得到"conguratulation php can call methods from java"的輸出可以進行下一步,否則重復(fù)上面的步驟。
4 SVN
TortoiseSVN 64位的1.7.10:http://tortoisesvn.net/downloads.zh.html
同時下載漢語言包進行安裝。
在http://tortoisesvn.net/support.zh.html svn使用幫助文檔。

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

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)

The settings.json file is located in the user-level or workspace-level path and is used to customize VSCode settings. 1. User-level path: Windows is C:\Users\\AppData\Roaming\Code\User\settings.json, macOS is /Users//Library/ApplicationSupport/Code/User/settings.json, Linux is /home//.config/Code/User/settings.json; 2. Workspace-level path: .vscode/settings in the project root directory

To correctly handle JDBC transactions, you must first turn off the automatic commit mode, then perform multiple operations, and finally commit or rollback according to the results; 1. Call conn.setAutoCommit(false) to start the transaction; 2. Execute multiple SQL operations, such as INSERT and UPDATE; 3. Call conn.commit() if all operations are successful, and call conn.rollback() if an exception occurs to ensure data consistency; at the same time, try-with-resources should be used to manage resources, properly handle exceptions and close connections to avoid connection leakage; in addition, it is recommended to use connection pools and set save points to achieve partial rollback, and keep transactions as short as possible to improve performance.

DependencyInjection(DI)isadesignpatternwhereobjectsreceivedependenciesexternally,promotingloosecouplingandeasiertestingthroughconstructor,setter,orfieldinjection.2.SpringFrameworkusesannotationslike@Component,@Service,and@AutowiredwithJava-basedconfi

itertools.combinations is used to generate all non-repetitive combinations (order irrelevant) that selects a specified number of elements from the iterable object. Its usage includes: 1. Select 2 element combinations from the list, such as ('A','B'), ('A','C'), etc., to avoid repeated order; 2. Take 3 character combinations of strings, such as "abc" and "abd", which are suitable for subsequence generation; 3. Find the combinations where the sum of two numbers is equal to the target value, such as 1 5=6, simplify the double loop logic; the difference between combinations and arrangement lies in whether the order is important, combinations regard AB and BA as the same, while permutations are regarded as different;

fixture is a function used to provide preset environment or data for tests. 1. Use the @pytest.fixture decorator to define fixture; 2. Inject fixture in parameter form in the test function; 3. Execute setup before yield, and then teardown; 4. Control scope through scope parameters, such as function, module, etc.; 5. Place the shared fixture in conftest.py to achieve cross-file sharing, thereby improving the maintainability and reusability of tests.

Python is an efficient tool to implement ETL processes. 1. Data extraction: Data can be extracted from databases, APIs, files and other sources through pandas, sqlalchemy, requests and other libraries; 2. Data conversion: Use pandas for cleaning, type conversion, association, aggregation and other operations to ensure data quality and optimize performance; 3. Data loading: Use pandas' to_sql method or cloud platform SDK to write data to the target system, pay attention to writing methods and batch processing; 4. Tool recommendations: Airflow, Dagster, Prefect are used for process scheduling and management, combining log alarms and virtual environments to improve stability and maintainability.

Use classes in the java.time package to replace the old Date and Calendar classes; 2. Get the current date and time through LocalDate, LocalDateTime and LocalTime; 3. Create a specific date and time using the of() method; 4. Use the plus/minus method to immutably increase and decrease the time; 5. Use ZonedDateTime and ZoneId to process the time zone; 6. Format and parse date strings through DateTimeFormatter; 7. Use Instant to be compatible with the old date types when necessary; date processing in modern Java should give priority to using java.timeAPI, which provides clear, immutable and linear

TheJVMenablesJava’s"writeonce,runanywhere"capabilitybyexecutingbytecodethroughfourmaincomponents:1.TheClassLoaderSubsystemloads,links,andinitializes.classfilesusingbootstrap,extension,andapplicationclassloaders,ensuringsecureandlazyclassloa
