I am about to go insane.
for hours, trying the same and does not work I have the following code:
<?php
exec('java -jar /home/user/classname.jar --some arguments',$output,$result);
works if I run from the command line, but if you get on my server and I try to run just does not work, I have tried with other command and work perfectly as "java -version", ls, mkdir, chmod, cp, date, etc