Jumi Call to Java

A multipurpose module, plugin and component

Jumi Call to Java

New postby stonkers » Tue Oct 06, 2015 7:46 pm

Hi! I'm attempting to call a java program from jumi php code. Here's my debug code:

Code: Select all
      $myResults = `/usr/bin/java -version`;
      echo "<pre>Results of Java Call</pre>";
      echo "<pre>$myResults</pre>";
      $myResults = `pwd`;
      echo "<pre>Results of pwd Call</pre>";
      echo "<pre>$myResults</pre>";
      $myResults = `which java`;
      echo "<pre>Results of which java Call</pre>";
      echo "<pre>$myResults</pre>";
      $myResults = `tail -10 /tmp/testfile.txt`;
      echo "<pre>Results of tail Call</pre>";
      echo "<pre>$myResults</pre>";
      $myResults = exec("/usr/bin/java -version");
      echo "<pre>Results of exec java Call</pre>";
      echo "<pre>$myResults</pre>";


And here are the results:

Results of Java CallResults of pwd Call/var/www/html/joomla
Results of which java Call/usr/bin/java
Results of tail CallTest file to see
how joomla reacts
to different commands
at an OS level...
Results of exec java Call


Does anyone have any ideas why I can't make a java call. I've tried to call a local bash script as well unsuccessfully.

Thanks,
Eric
stonkers
 
Posts: 4
Joined: Wed Feb 09, 2011 10:31 pm

Re: Jumi Call to Java

New postby [email protected] » Wed Oct 07, 2015 7:17 pm

I've tried some other stuff like using exec, but no help:

Code: Select all
      exec("/usr/bin/java -version" , $cmdOutput , $return_var );
      echo "<pre>Results of exec java Call</pre>";
      echo "<pre>";
      foreach ($cmdOutput as $val) {
         echo $val;
      }
      echo "</pre>";
      echo "<pre>Return Value is:  $return_var</pre>";
      
      exec("pwd" , $cmdOutput , $return_var );
      echo "<pre>Results of exec pwd Call</pre>";
      echo "<pre>";
      foreach ($cmdOutput as $val) {
         echo $val;
      }
      echo "</pre>";
      echo "<pre>Return Value is:  $return_var</pre>";


Results are:

Results of exec java Call
Return Value is: 0
Results of exec pwd Call
/var/www/html/joomla
Return Value is: 0


The thing is, in another part of the code I successfully call java. But this is a function that is called by an ajax form from the java script on the page. Doesn't seem it should make a difference to me but it does. The only difference with the code is that it includes a classpath. I've tried adding that but it didn't help...
[email protected]
 
Posts: 5
Joined: Tue Apr 05, 2011 2:48 am

Re: Jumi Call to Java

New postby Edvard » Wed Oct 07, 2015 7:49 pm

Hi,

You probably won't be able to call to scripts not inside your PHP open basedir. Also you may have PHP safe mode on. It may be permission issue as well.

Please check your PHP error log and probably you will find more info why the exec doesn't work there.

This is not Jumi related.

Thanks!
Regards,

Edvard Ananyan - 2GLux Team

Please post a review at the Joomla Extensions Directory. It is very important for us!
Edvard
Site Admin
 
Posts: 1836
Joined: Mon Jun 28, 2010 1:54 pm
Location: Yerevan, Armenia

Re: Jumi Call to Java

New postby [email protected] » Wed Oct 07, 2015 8:04 pm

Edvard,

Thank you for your reply. Safe mode is off. Permissions are fine, 755 and owned by the apache user. As that user I can perform java calls all day long. Why would it work to call java in one part of the jumi code but not another?
[email protected]
 
Posts: 5
Joined: Tue Apr 05, 2011 2:48 am

Re: Jumi Call to Java

New postby [email protected] » Wed Oct 07, 2015 9:37 pm

OK, well not sure what I've changed, but it works to call the command directly now:

$results = `java -cp classpath:pathToJarname.jar -jar jarname.jar -argument1 value -argument2 value`;

The only thing I've chaged from the beginnins was to add the -cp classpath which hardly seems necessary as this is a direct call to the jar file... Thanks for helping!
[email protected]
 
Posts: 5
Joined: Tue Apr 05, 2011 2:48 am


Return to Jumi

Who is online

Users browsing this forum: No registered users and 8 guests

cron