Search code examples
spring-bootrelative-pathexecutable-jarpicocli

How to use relative-path-parameter with Spring Boot/picocli executable jar?


I have a command line application, which uses Spring Boot and picocli. It is possible to pass parameter, which is a path, e.g. myApp.jar /path/to/file and it will do something with this file. I want to use this app system-wide, so I placed the executable .jar in /usr/bin/ and renamed it to myApp.

Now, when I use it with absolute path: myApp /home/user/file it works fine, but I want to pass relative path, e.g. when I am in /home/user/ I want it to be myApp ./file. The problem is that with relative path it tries to use /usr/bin/file instead of /home/user/file.

The workaround I use currently is something like this: myApp $(pwd)/file.

Do you have some idea how to fix this?


Solution

  • Ok, so I've managed to resolve the issue by using custom launch script for Spring Boot

    I've copied original sources and removed lines responsible for working directory change:

    run() {
      pushd "$(dirname "$jarfile")" > /dev/null # <-- removed
      "$javaexe" "${arguments[@]}"
      result=$?
      popd > /dev/null # <-- removed
      return "$result"
    }
    

    I am not very happy with this solution, but it is better than nothing.