Executing jar file from PHP not working

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Executing jar file from PHP not working

Postby chrisp83 » 16. March 2011 17:07

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
chrisp83
 
Posts: 4
Joined: 16. March 2011 16:59

Re: Executing jar file from PHP not working

Postby Sharley » 17. March 2011 02:33

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. :)
User avatar
Sharley
AF Moderator
 
Posts: 3316
Joined: 03. October 2008 05:10
Location: Yeppoon, Australia Time Zone: GMT/UTC+10
Operating System: Win 7 Pro 32bit/XP Pro SP3

Re: Executing jar file from PHP not working

Postby chrisp83 » 17. March 2011 11:29

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
chrisp83
 
Posts: 4
Joined: 16. March 2011 16:59

Re: Executing jar file from PHP not working

Postby chrisp83 » 18. March 2011 16:35

I haven't found the solution in the links you gave me. Does anybody has a suggestion?
chrisp83
 
Posts: 4
Joined: 16. March 2011 16:59

Re: Executing jar file from PHP not working

Postby WilliL » 18. March 2011 19:36

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";
Willi
WilliL
 
Posts: 661
Joined: 08. January 2010 10:54
Operating System: Win7Home Prem 64 SP1

Re: Executing jar file from PHP not working

Postby chrisp83 » 21. March 2011 15:56

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!
chrisp83
 
Posts: 4
Joined: 16. March 2011 16:59

Re: Executing jar file from PHP not working

Postby Gunjan » 02. May 2014 18:03

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
Gunjan
 
Posts: 2
Joined: 01. June 2013 16:11
Operating System: Windows 7


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 32 guests