Page 1 of 1

Executing jar file from PHP not working

PostPosted: 16. March 2011 17:07
by chrisp83
I'm working on a project where i need to start a jar file from PHP. I've used the exec() and system() function but i keep getting a error:

IO Exception while starting Log Couldn't get lock for log/logFile.log

My directory structure is

htdocs/simulation/gui/script.php
htdocs/simulation/java/jarFile.jar

I think this has something to do with file permissions, i know how to change user permissions, but for which user do you need to change it?

Code: Select all
   exec("java -jar ./../java/EMS2.jar", $output);
   print_r($output);   


I have also used the absolute path (c:/www/xampp/htdocs/simulation/java/EMS2.jar)

Does anybody have a suggestion?

PS. The jar file works perfect from the commandline

Re: Executing jar file from PHP not working

PostPosted: 17. March 2011 02:33
by Sharley
chrisp83 wrote:but i keep getting a error:

IO Exception while starting Log Couldn't get lock for log/logFile.log
Only a guess here but this error seems to indicate that the folder or path to where the log file is created does not have permission to be written by the server as the lock file is created before the log file is created.

Perhaps check the log file path in the jar file.

Any clues in the Apache \xampp\apache\logs\error.log file, also you can turn on php error logging in the php.ini file, remember to restart Apache if you make php.ini changes.

Above info source
http://www.velocityreviews.com/forums/

Log file tut:
http://www.developerzone.biz

Hope this post helps. :)

Re: Executing jar file from PHP not working

PostPosted: 17. March 2011 11:29
by chrisp83
Thanks for your reply.

In the Apache log i found the following error:
Code: Select all
17-mrt-2011 11:06:44 org.project.common.Settings loadFromFile
SEVERE: settings.ini (Het systeem kan het opgegeven bestand niet vinden) // that's dutch for "The system can not find the file"
java.io.IOException: Couldn't get lock for log/log.log
    at java.util.logging.FileHandler.openFiles(Unknown Source)
    at java.util.logging.FileHandler.<init>(Unknown Source)
    at org.project.common.Log.init(Log.java:37)
    at org.project.common.Log.<clinit>(Log.java:27)
    at org.project.common.MessageBus.init(MessageBus.java:31)
    at org.project.common.MessageBus.<clinit>(MessageBus.java:27)
    at org.project.launcher.Launcher.<init>(Launcher.java:26)
    at org.project.launcher.Launcher.main(Launcher.java:36)
17-mrt-2011 11:06:44 com.sun.messaging.jmq.jmsclient.ExceptionHandler logCaughtException
WARNING: [I500]: Caught JVM Exception: java.lang.NumberFormatException: For input string: "null"
17-mrt-2011 11:06:44 org.flexines.common.MessageBus init
SEVERE: [C4038]: java.lang.NumberFormatException: For input string: "null"
Exception in thread "main" java.lang.NullPointerException
    at org.project.common.MessageBus.start(MessageBus.java:59)
    at org.project.launcher.Launcher.<init>(Launcher.java:26)
    at org.project.launcher.Launcher.main(Launcher.java:36)


When i start the java application in the console it works perfectly, but from PHP i get these errors. I haven't developed the Java app, so i can't modify it. Has is got something to do with the paths in the java app?

Java uses relative paths?

Thanks for your reply and suggestions, i'm currently reading the links you gave me. I'll keep you updated

Re: Executing jar file from PHP not working

PostPosted: 18. March 2011 16:35
by chrisp83
I haven't found the solution in the links you gave me. Does anybody has a suggestion?

Re: Executing jar file from PHP not working

PostPosted: 18. March 2011 19:36
by WilliL
I would try absolute path
Code: Select all
// if(exec("java -jar c://xampp//apache//htdocs//simulation//java//EMS2.jar", $output))
if(exec("java -jar c:/xampp/apache/htdocs/simulation/java/EMS2.jar", $output))
   print_r($output);
else echo "failed";

it's just a guess, - the error suggests to a wrong path or not existing file

edit: I would check too:
Code: Select all
$to_execute="java -jar c:/xampp/apache/htdocs/simulation/java/EMS2.jar";
if(exec($to_execute, $output))
   print_r($output);
else echo "failed";

Re: Executing jar file from PHP not working

PostPosted: 21. March 2011 15:56
by chrisp83
Thanks for your reply,

i found the solution!

PHP executes the jar file relative from the script folder. Using the & i created two commands. The first one to go to the right folder, the second to start the jar file.

Code: Select all
$to_execute="cd./../java/ & java -jar EMS2.jar";
$last_line = system($to_execute, $output);
echo $output. "<br />";


Thanks for your help!

Re: Executing jar file from PHP not working

PostPosted: 02. May 2014 18:03
by Gunjan
Hi,

I tried doing the same thing.. i have my .php file and jar file in same folder
htdocs/portal/dist/testing.php
htdocs/portal/dist/javaapp.jar

in testing.php i copied the code you mentioned.. but it doesnt work for me.. on double clicking the jar file from the above mentioned folder it works.
But running the php file doesnt do anything. it do not produce any error also.. the php script runs. but no output is shown.

can you please help me on how to make it run
thaks in advance