0

I have a web page written in html and php and I use a java program at the backend to update a database. My java program works fine in the eclipse(as a standalone) and I was able to update the database.When used in php I have compiled my java programs with jar file and have run it in php using shell_exec command.

$java_cmd = 'java -cp java-resource/opencsv-2.1-1.0.0.jar:java-resource/xerces-2_6_2.jar:java-resource/commons-codec-1.6.jar:java-resource/.  UpdateDNNumber';
$content = shell_exec($java_cmd);

Now when I submit in the webpage nothing happens at the backend. I am not able to update database and couldn't see any logs in my query log page that i have created. i have given full 777 permissions for my php,html and java class files and source files. I have enabled firebug and have saw the post and response field it shows it takes the correct options. I am troubleshooting in java and php side.Not sure what may be the exact issue.I am the only developer in my team so don't have any one to discuss. Can you anyone of you suggest as how I take this forward?Not asking any code help just inputs on troubleshooting..

Thanks your help is much appreciated.

nanofarad
  • 40,330
  • 4
  • 86
  • 117
javalearner
  • 197
  • 2
  • 4
  • 16
  • Have you tried to run that exact command in a shell to see if it fails? – nanofarad Aug 21 '14 at 17:32
  • Try putting the actual path to the `java` binary, maybe it's not reading from your `path` environment variable. – Adam Aug 21 '14 at 17:33
  • No, I will try it... – javalearner Aug 21 '14 at 17:34
  • Java depends on some environment variables to work correctly in most cases. `JAVA_HOME` for instance. – amphetamachine Aug 21 '14 at 17:35
  • Are you switching to the directory containing your Java resources beforehand? If not, then `java` may simply not be finding your `jar` and `.class` files... – thkala Aug 21 '14 at 17:36
  • @amphetamachine: it works fine on my Linux system without any `JAVA*` or `CLASS*` variables in the environment. – thkala Aug 21 '14 at 17:37
  • i have a php file inside a folder and java-resource is a subfolder in which i have my jar files and source files.I have compiled the files in my local and have copied the source files and class files in a server.(Made sure the path is pointing to the server) – javalearner Aug 21 '14 at 17:41
  • @javalearner: uh... does the server have Java? If it is on a PHP hosting provider it will probably not have a JRE installed, let alone a recent one... – thkala Aug 21 '14 at 17:56
  • Yes the server has java. One of my colleague created a similar tool like mine.So i am using the same folder and almost same php file except the java coding part.His tool works like a charm. Mine is not working.I am comparing but still couldnt narrow down.He left the company so will not be able to consult. – javalearner Aug 21 '14 at 18:01
  • @javalearner: you should probably enable debugging on your PHP page and check your web server logs. Otherwise we are just taking very long shots into the dark... – thkala Aug 21 '14 at 18:15
  • Sure thkala, I am doing that. Thanks for all your suggestions. I have enabled firebug and debugging. I ll let u know if I find out..Thanks again. – javalearner Aug 21 '14 at 18:31
  • @javalearner: By *"enable debugging"* I mean on the *server* side... – thkala Aug 21 '14 at 18:41
  • How do I do that ?on the server side? – javalearner Aug 21 '14 at 18:48
  • @javalearner, [try this](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php) – Adam Aug 21 '14 at 18:51
  • Can anybody tell me how to compile jar files with source files in a unix server.I have compiled it in my local and then I have copied the same class file.I guess that's the reason the php file is not detecting my java file. I tried compiling as follows but doesn't take jar files and throws errors that are pertaining to the jar files – javalearner Aug 25 '14 at 17:27
  • javac -cp ".;/var/www/cgi-bin/update-user-cm/java-resource/commons-codec-1.6.jar;/var/www/cgi-bin/update-user-cm/java-resource/opencsv-2.1-1.0.0.jar;/var/www/cgi-bin/update-user-cm/java-resource/xerces-2_6_2.jar;" UpdateDNNumber.java i compiled as this and getting error as it didnt take the jar files – javalearner Aug 25 '14 at 17:29

1 Answers1

0

I have finally found out the issue and fixed it.. It was a simple error.I had compiled the program in my local and copied the same class file to the server so that path is wrong.I compiled it as follows in the server and it worked like a charm.

javac -cp '.:/var/www/cgi-bin/update-user-cm/java-resource/commons-codec-1.6.jar:/var/www/cgi-bin/update-user-cm/java-resource/opencsv-2.1-1.0.0.jar:/var/www/cgi-bin/update-user-cm/java-resource/xerces-2_6_2.jar' UpdateDNNumber.java

it worked fine. Thanks for all your help and suggestions..

javalearner
  • 197
  • 2
  • 4
  • 16