Results 1 to 4 of 4
  1. #1
    doomsword2001 is offline Member
    Join Date
    Nov 2010
    Posts
    15
    Rep Power
    0

    Default set current dir to project/bin

    hello,

    i made a java application which writes a file to the hard disk. The jar file is placed in /home/myname/workspace.

    If i run the jar file(right click open with jre), the file is saved on /home/myname. But if i create a script run.sh (which includes java -jar myfile.jar) and run the project with it, it saves the files on the project dir.

    Is there any way to set the current dir to the app's dir?
    I dont want to say System.setProperty("user.dir", "/home/myname/workspace"); because the users who'll use the software should be able to run in no matter of the dir it is in.

    If there's no way to do it in java, can anybody tell me how to create executable files like my run.sh for windows and mac ? I think windows is called .bat file. I know that would work because current dir is the dir the jar file was opened from.

    thx :]

  2. #2
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    I usually do something like this by passing the desired dir as a command line argument that's read by my Java program's main method. Since I run things on Windows, I then create a short cut that sends the Jar file the correct parameter.

  3. #3
    doomsword2001 is offline Member
    Join Date
    Nov 2010
    Posts
    15
    Rep Power
    0

    Default

    clever, thx, i'll do it that way, much better approach

  4. #4
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    Quote Originally Posted by doomsword2001 View Post
    clever, thx, i'll do it that way, much better approach
    You're welcome.

Similar Threads

  1. Applet - get current URL
    By Dennis in forum Advanced Java
    Replies: 4
    Last Post: 06-13-2010, 02:26 PM
  2. Current month
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-07-2008, 09:40 AM
  3. Getting current userís name
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-07-2007, 01:04 PM
  4. How to get the current working directory in EJB?
    By sathish_2111 in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 07-19-2007, 05:24 PM
  5. How can i get current directory?
    By Ashley in forum New To Java
    Replies: 1
    Last Post: 05-26-2007, 02:21 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
  •