Skip to content

Instantly share code, notes, and snippets.

@gkhays
Created February 15, 2020 14:53
Show Gist options
  • Save gkhays/917a938ef8f71fdcea4811390d528674 to your computer and use it in GitHub Desktop.
Save gkhays/917a938ef8f71fdcea4811390d528674 to your computer and use it in GitHub Desktop.
Get the path of a running JAR file

The .toURI() method allows you to sidestep issues with special characters.

return new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation()
    .toURI()).getPath();

References

How to get the path of a running JAR file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment