Question

I have a system which is implemented using PHP(Joomla). Now the client wants to integrate a SMS gateway. Unfortunately SMS gateway does not supoort PHP. It's written in Java and All the examples are written in JAVA.

I'm supposed to include webservices‐rt.jar to my program and run a example script as below.

lk.mobitel.esms.User user = new lk.mobitel.esms.User (); user.setUsername(“TestUser”);
user.setPassword(“Password”);
lk.mobitel.esms.test.ServiceTest st = new lk.mobitel.esms.test.ServiceTest (); 
System.out.println(st.testService(u));

According to my knowledge I can run a .jar as below using PHP

<?php exec("java -jar filename.jar arguments",$output); ?>

How can I run a JAVA script like above in PHP? Is it possible? Is there a way to bridge PHP and JAVA? What I want is to run JAVA in PHP else I would say communicate between these two.

Was it helpful?

Solution

I never did this, but PHP Manual gave a link for PHP-Java Bridge for PHP5 as PHP/Java Bridge. If it is what you are looking for ?

OTHER TIPS

It's not possible to combine PHP and Java in the same script and have them executed in one run.

Your exec approach is the way to go, if you are approaching from PHP. But you should rather use passthru as exec does not return anything. With passthru you can get the shell response of your java command and act accordingly.

Is there a way to bridge PHP and JAVA? What I want is to run JAVA in PHP else I would say communicate between these two.

Simple answer:

Bridge using data-exchange layer. :)

Hint (in super simple language): My favorite webservice uses PERL to process their scripts and I fetch them using XML. Groupon is made on RoR but, I happily get tweets, thanks to their API which outputs a JSON.

Simple? :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top