Skip to main content

How to deploy your PHP and Java file in PHP/JavaBridge

Here I explain how to deploy your PHP and Java file in your PHP/JavaBridge folder.
You may need basic knowledge of Linux command, PHP, Java, Tomcat.

Please use the link below to go to further reading if necessary.

V. Deploy your PHP and Java file
In this chapter, I will not talk detail about how to create and run Java.
If you are curious about how to create PHP that executes Java, check PHP/JavaBridge site.

1. Create Java Hello World
1.1. Open eclipse and create Java Project.
1.2. Create HelloWorld.java file under the project.
import javax.swing.JOptionPane;

public class HelloWorld {
    public static final String JAVABRIDGE_PORT="8080";
    static final php.java.bridge.JavaBridgeRunner runner = php.java.bridge.JavaBridgeRunner.getInstance(JAVABRIDGE_PORT);

    public static void main(String args[]) throws Exception {
        runner.waitFor();
        System.exit(0);
    }
    public void hello(String args[]) throws Exception {
        JOptionPane.showMessageDialog(null, "hello " + args[0]);
    }
}
1.3. Create MANIFEST.MF
Main-Class: HelloWorld
Class-Path: JavaBridge.jar
1.4. Add JavaBridge.jar into Build Path.
Right click on the project and go to Build Path.
Add JavaBridge.jar file on library tab.

1.5. Built and Run
Make sure Project -> Build Automatically is checked on eclipse.
Right click on your project, and choose Run -> Java Application.

You will see no result, and it is ok for now. Just make sure it run without error.
1.6. Create TestBridge.jar file.
Right click on the project and choose Export to the executable jar file.


2. Create test php file
Create mytest.php under JavaBridge folder, which contains following code.
<?php
require_once("http://localhost:8080/JavaBridge/java/Java.inc");

$world = new java("HelloWorld");
echo $world->hello(array("from PHP"));
?>


3. Deploy jar file
Place TestBridge.jar under JavaBridge/WEB-INF/lib/


4. Set up CGI on the web
4.1. Go to Tomcat directry
Open Finder and go to your tomcat directory, such as /usr/local/apache-tomcat-{your version}/.
4.2. Edit conf/web.xml file
Open conf/web.xml file on any text editer and comment out for and tags.
If you have any problem, here is the Tomcat site that guide you how to set up CGI more detail.

5. Change php.ini
5.1. Go to PHP folder
Go to PHP directory, such as /opt/local/etc/php53/.
5.2. Edit php.ini file
Open php.ini file on text editer and add following line.
allow_url_include = On

6. Restart Tomcat
If you have not set up Tomcat on your local machine, here is II. How to install Tomcat.
/Library/Tomcat/bin/startup.sh
/Library/Tomcat/bin/shutdown.sh

7. Check the result
Go to http://localhost:8080/JavaBridge/mytest.php and you will see your jar file is executed.


If you have any suggestion and question, especially technically and grammatically, please feel free to leave your comment.

Thank you for your visit😊

Comments

Popular posts from this blog

Postgresに初期データを投入

1.Linuxユーザの作成 postgresで設定したユーザをLinuxユーザとしても追加する必要があります。 これをしないとCOPYが実行できません。 adduser postgresusr 2.CSVファイルの配置 WinSCPを使用してCSVファイルをアップロード 所定のフォルダにCSVファイルを配置する。 3.CSVファイルへの権限付与 CSVファイルに権限付与を実施。 chmod -R 777 /home/linux/data (全権限付与でなくても実行可能なはず) 4.Postgresにログイン psql -h localhost -U postgresusr -d postgresdb 3.COPYコマンド実行 COPY TEST FROM '/home/linux/data/test.csv' WITH CSV; 4.SQLファイル実行 \i /home/linux/data/template.sql ○参考サイト http://www.dbonline.jp/postgresql/connect/index2.html http://okwave.jp/qa/q6807324.html http://itpro.nikkeibp.co.jp/article/COLUMN/20060227/230728/ http://homepage3.nifty.com/nasunu-i/LinuxBeginner/Permission.htm http://sasuke.main.jp/postgrescmd.html

How to install PHP and CGI on your Mac 

Here I explain how to install PHP and CGI on your . You may need basic knowledge of Linux command, PHP , Java , Tomcat . Please use the link below to go to further reading if necessary. I. How to install Java II. How to install Tomcat III. How to install PHP and CGI IV. How to deploy PHP/JavaBridge V. How to deploy your PHP and Java files III. How to install PHP and CGI 1. Check PHP and CGI are installed 1.1. Check PHP version Open Terminal and enter following command. php -v You can also find out where is php.ini by entering these following command. which php whereis php 1.2. Check CGI version php-cgi If you see your result as below, you have already installed PHP and CGI. If not, follow next step. 2. Install XCode In order to use Port , you need to install XCode first. Open AppStore and install XCode . Make sure you run XCode after the installation. 3. Install Port Here I show How to install Port . If you have Brew , go head and use it instead of P...