Results 1 to 11 of 11
  1. #1
    AndyVidk is offline Member
    Join Date
    Oct 2011
    Posts
    13
    Rep Power
    0

    Question getRuntime().exec(run) in Linux. a path related problem?

    I'm currently working from a Ubuntu platform with the Eclipse IDE.

    I have exported 2 runnable jar's. and one should exec the other. Im using the bellow snippet for this
    Java Code:
    String run[] = {"java", "-jar", "update/update.jar"};
                Runtime.getRuntime().exec(run);
    If i run this inside the eclipse IDE, by creating a folder in the project with the jar(update/update.jar) then it works just fine. But if i try to run this in another folder such as home/me/desktop/projekt_folder/ it will not. i have tried to debug this and maybe i'm wrong but a syso on a .getPath tells me that the working directory is home/me. Maybe this is the problem, but i cant figure of a solution.

    I have spent many hours on this issue and i simply cannot find the solution, any input is greatly appreciated !

    Note the folder structure inside the root folder/ projectfolder is:
    ../mainjar.jar
    ../update/update.jar
    Last edited by AndyVidk; 10-08-2011 at 09:17 PM.

  2. #2
    Join Date
    Aug 2011
    Location
    Pretoria, South Africa
    Posts
    27
    Blog Entries
    3
    Rep Power
    0

    Default Re: getRuntime().exec(run) in Linux. a path related problem?

    I might be going over my head hear... but have you tried setting the string to
    Java Code:
    String run[] = {"java", "-jar", "./update/update.jar"}

  3. #3
    AndyVidk is offline Member
    Join Date
    Oct 2011
    Posts
    13
    Rep Power
    0

    Default Re: getRuntime().exec(run) in Linux. a path related problem?

    Quote Originally Posted by DuvanSlabbert View Post
    I might be going over my head hear... but have you tried setting the string to
    Java Code:
    String run[] = {"java", "-jar", "./update/update.jar"}


    I tried it out, but unfortunately it did not solve my issue.

  4. #4
    Join Date
    Aug 2011
    Location
    Pretoria, South Africa
    Posts
    27
    Blog Entries
    3
    Rep Power
    0

    Default Re: getRuntime().exec(run) in Linux. a path related problem?

    Have you tried to surrounding the

    Java Code:
    Runtime.getRuntime().exec(run);
    With a try catch exception, like so?

    Java Code:
    try {
    			Runtime.getRuntime().exec(run);
    		} catch (IOException exc) {
    			exc.printStackTrace();
    		}
    and then if you get an exception in the runtime of eclipse to post that exception on the forum...

  5. #5
    AndyVidk is offline Member
    Join Date
    Oct 2011
    Posts
    13
    Rep Power
    0

    Default Re: getRuntime().exec(run) in Linux. a path related problem?

    Quote Originally Posted by DuvanSlabbert View Post
    Have you tried to surrounding the

    Java Code:
    Runtime.getRuntime().exec(run);
    With a try catch exception, like so?

    Java Code:
    try {
    			Runtime.getRuntime().exec(run);
    		} catch (IOException exc) {
    			exc.printStackTrace();
    		}
    and then if you get an exception in the runtime of eclipse to post that exception on the forum...

    Thats how it is now. But the issue, does not show it self when executing through the Eclipse. ~ No exception is thrown.

    EDIT: In The eclipse environment it works. But when i export to runnable jar's it does not.


    EDIT I tried parsing the exception to a JOptionPane so that i would be able to see the message. But it seems that a exception is never thrown.
    Last edited by AndyVidk; 10-08-2011 at 07:56 PM.

  6. #6
    Join Date
    Aug 2011
    Location
    Pretoria, South Africa
    Posts
    27
    Blog Entries
    3
    Rep Power
    0

    Default Re: getRuntime().exec(run) in Linux. a path related problem?

    and you sure that in the directory of the jar file "home/me/desktop/projekt_folder/mainjar.jar" there is also a the "update" folder witch contains the update.jar file??? if so, then like I said, went in over my head here. sry man.

  7. #7
    AndyVidk is offline Member
    Join Date
    Oct 2011
    Posts
    13
    Rep Power
    0

    Default Re: getRuntime().exec(run) in Linux. a path related problem?

    Quote Originally Posted by DuvanSlabbert View Post
    and you sure that in the directory of the jar file "home/me/desktop/projekt_folder/mainjar.jar" there is also a the "update" folder witch contains the update.jar file??? if so, then like I said, went in over my head here. sry man.
    Yes i'm sure. Don't be, input is always appreciated .

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default Re: getRuntime().exec(run) in Linux. a path related problem?

    Quote Originally Posted by AndyVidk View Post
    I'm currently working from a Ubuntu platform with the Eclipse IDE.

    I have exported 2 runnable jar's. and one should exec the other. Im using the bellow snippet for this
    Java Code:
    String run[] = {"java", "-jar", "update/update.jar"};
                Runtime.getRuntime().exec(run);
    If i run this inside the eclipse IDE, by creating a folder in the project with the jar(update/update.jar) then it works just fine. But if i try to run this in another folder such as home/me/desktop/projekt_folder/ it will not. i have tried to debug this and maybe i'm wrong but a syso on a .getPath tells me that the working directory is home/me. Maybe this is the problem, but i cant figure of a solution.
    If your cwd (current working directory) is /home/me there should be a jar file at /home/me/update/update.jar; is it there?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    AndyVidk is offline Member
    Join Date
    Oct 2011
    Posts
    13
    Rep Power
    0

    Default Re: getRuntime().exec(run) in Linux. a path related problem?

    Quote Originally Posted by JosAH View Post
    If your cwd (current working directory) is /home/me there should be a jar file at /home/me/update/update.jar; is it there?
    kind regards,
    Jos
    Well, no. But its is also wrong, it is not where i run my project from. So it should not be my working directory.



    I have tried to run project on an other OS and it seems to work just fine.
    I Think the problem might be that i am using OpenJDK instead of JDK7, I haven't had time to test this yet thought.

    Thank you all for your input in this matter.

    Regards, Andy

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default Re: getRuntime().exec(run) in Linux. a path related problem?

    Don't make stuff more complicated than needed; if you run your program (java.exe actually) in a directory X that directory needs to have a subdirectory and jar file stored here: X/update/update.jar, otherwise java.exe can't find any jar file.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    AndyVidk is offline Member
    Join Date
    Oct 2011
    Posts
    13
    Rep Power
    0

    Exclamation Re: getRuntime().exec(run) in Linux. a path related problem?

    SOLVED:

    It seems that when running a jar, there are no certainties that the current working directory will be where the jar is located. To solve this i will have to set the full path to execute the jar. Now you might think that this can be done with a simple getPath() - but it cannot because the current working path will be (in linux) $user/home.

    The full path can be obtained with:
    Java Code:
     
            Class cls = this.getClass();
        	ProtectionDomain pDomain = cls.getProtectionDomain();
        	CodeSource cSource = pDomain.getCodeSource();
        	URL loc = cSource.getLocation();
    Last edited by AndyVidk; 10-10-2011 at 10:18 AM.

Similar Threads

  1. getRuntime().exec Doesn't Work in FireFox.
    By noJava in forum Java Applets
    Replies: 5
    Last Post: 02-25-2011, 01:39 PM
  2. Runtime.getRuntime().exec() and pppd
    By mysticav in forum Networking
    Replies: 7
    Last Post: 02-15-2011, 07:44 PM
  3. problem with Runtime.getRuntime().exec when running java in .bat
    By Shayko in forum Threads and Synchronization
    Replies: 2
    Last Post: 01-27-2010, 07:46 PM
  4. help with Runtime.getRuntime().exec
    By collin389 in forum AWT / Swing
    Replies: 3
    Last Post: 11-09-2009, 04:22 AM
  5. Problem with Runtime.getRuntime().exec with Linux Commands
    By swapnilnawale in forum Threads and Synchronization
    Replies: 1
    Last Post: 09-23-2009, 10:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •