System.getProperty("user.dir") might be inadequate

Issue #465 resolved
Desrever Nu created an issue

when running from the jar, it returns the directory from where the jar has been launched, which in a normal condition works fine

$ cd /path/to/dist/
$ java -jar NuBot.jar

System.getProperty("user.dir") will return /path/to/dist/

however, if the user does the following

$ cd /one/random/path/on/system
$ java -jar /path/to/dist/NuBot.jar

System.getProperty("user.dir") will be /one/random/path/on/system

possible solution http://stackoverflow.com/questions/4871051/getting-the-current-working-directory-in-java . Beware it might work differently when launching inside the IDE

Comments (4)

  1. Desrever Nu reporter

    implemented FileSystem.getBotAbsolutePath();

     @return a String with the absolute path of the folder.
     If used inside the IDE will use System.getProperty("user.dir")
     If used from the jar will return the absolute path of the jar
    
  2. Desrever Nu reporter

    I am now going to systematically replace all the occurrences of System.getProperty("user.dir") with FileSystemUtils.getBotAbsolutePath()

  3. Log in to comment