Javabridge is the bridge between the PHP and Java. If we need Java libraries in PHP, then we implement the Javabridge concept.
Requirements :
1) JDK
2) PHP
3) Apache
4) Tomcat
5) Javabridge war folder
STEP 1 : Download and install the JDK latest version.
STEP 2 : Once installation completed, set the Environment variables.
Right click on MyComputer -> Properties -> Advanced -> Environment variables -> Double click on path, then add the bin path, like below
STEP 3 : Then check java is running or not in our system. For checking we can use command prompt. Like C:\> javac.
Once we get the below screen, then we successfully compile the java.
STEP 4 : Now you can install the PHP, Apache and tomcat servers. Other wise you can use XAMPP or WAMP Servers. Once install the Xampp server you can run the Apache, MySql and Tomcat services.
In this example we deal with XAMPP server.
STEP 5 : Now we set 2 environments. One is PHP & another one is Java.
In PHP environment, you can create one project (JavaBridge) in xampp/htdocs folder. And also create index.php with below code.
<?php
//init php java bridge
require_once "E://Testing/xampp/tomcat/webapps/JavaBridge/java/Java.inc";
$class = new JavaClass("java.lang.Class");
$class->forName("com.mysql.jdbc.Driver");
$driverManager = new JavaClass("java.sql.DriverManager");
if($driverManager)
echo "Success";
else
echo "Failure";
?>
STEP 6 : Download the JavaBridge.war at http://php-java-bridge.sourceforge.net/doc/download.php
STEP 7 : Create JavaBridge folder at xampp/tomcat/webapps location, Then move the downloaded war file(JavaBridge.war) to xampp/tomcat/webapps/JavaBridge folder.
STEP 8 : Now you can go to command prompt webapps location (xampp\tomcat\webapps\)
And run the war file. Like below
jar -xvf \JavaBridge.war
Here all the JavaBridge files will be extracted.
STEP 9 : Check the tomcat library files at xampp\tomcat\lib folder. For JavaBridge we must need the recommended jar file (Those files are highlighted).
If any thing is missing you can download and located at lib folder.
commons-collections-3.2.1.jar
commons-beanutils-1.9.2.jar
commons-digester-2.1.jar
commons-logging-1.2.jar
groovy-all-1.5.5.jar
itext-2.1.7.jar
jasperreports-6.0.4.jar (or)
jasperreports.jar
mysql-connector-java.jar (or)
mysql-connector-java-5.1.37-bin.jar
STEP 10 : If everything is fine check the tomcat JavaBridge. (http://localhost:8080/JavaBridge)
STEP 11 : If we got the Javabridge Page, Run the PHP application (http://localhost/JavaBridge). You can get the Success message.
Good Luck !
Requirements :
1) JDK
2) PHP
3) Apache
4) Tomcat
5) Javabridge war folder
STEP 1 : Download and install the JDK latest version.
STEP 2 : Once installation completed, set the Environment variables.
Right click on MyComputer -> Properties -> Advanced -> Environment variables -> Double click on path, then add the bin path, like below
C:\Java\jdk1.7.0\bin;
STEP 3 : Then check java is running or not in our system. For checking we can use command prompt. Like C:\> javac.
Once we get the below screen, then we successfully compile the java.
STEP 4 : Now you can install the PHP, Apache and tomcat servers. Other wise you can use XAMPP or WAMP Servers. Once install the Xampp server you can run the Apache, MySql and Tomcat services.
In this example we deal with XAMPP server.
STEP 5 : Now we set 2 environments. One is PHP & another one is Java.
In PHP environment, you can create one project (JavaBridge) in xampp/htdocs folder. And also create index.php with below code.
<?php
//init php java bridge
require_once "E://Testing/xampp/tomcat/webapps/JavaBridge/java/Java.inc";
$class = new JavaClass("java.lang.Class");
$class->forName("com.mysql.jdbc.Driver");
$driverManager = new JavaClass("java.sql.DriverManager");
if($driverManager)
echo "Success";
else
echo "Failure";
?>
STEP 6 : Download the JavaBridge.war at http://php-java-bridge.sourceforge.net/doc/download.php
STEP 7 : Create JavaBridge folder at xampp/tomcat/webapps location, Then move the downloaded war file(JavaBridge.war) to xampp/tomcat/webapps/JavaBridge folder.
STEP 8 : Now you can go to command prompt webapps location (xampp\tomcat\webapps\)
And run the war file. Like below
jar -xvf \JavaBridge.war
Here all the JavaBridge files will be extracted.
STEP 9 : Check the tomcat library files at xampp\tomcat\lib folder. For JavaBridge we must need the recommended jar file (Those files are highlighted).
If any thing is missing you can download and located at lib folder.
commons-collections-3.2.1.jar
commons-beanutils-1.9.2.jar
commons-digester-2.1.jar
commons-logging-1.2.jar
groovy-all-1.5.5.jar
itext-2.1.7.jar
jasperreports-6.0.4.jar (or)
jasperreports.jar
mysql-connector-java.jar (or)
mysql-connector-java-5.1.37-bin.jar
STEP 10 : If everything is fine check the tomcat JavaBridge. (http://localhost:8080/JavaBridge)
STEP 11 : If we got the Javabridge Page, Run the PHP application (http://localhost/JavaBridge). You can get the Success message.
Good Luck !
No comments:
Post a Comment