Skip to content

Instantly share code, notes, and snippets.

@bhattisatish
Created May 3, 2010 08:26
Show Gist options
  • Save bhattisatish/387873 to your computer and use it in GitHub Desktop.
Save bhattisatish/387873 to your computer and use it in GitHub Desktop.
// Provides the URL for the location of your executing code for a given class.
ProtectionDomain protectionDomain = MyClass.class.getProtectionDomain();
URL location = protectionDomain.getCodeSource().getLocation();
location.toExternalForm();
OR
File codeLoc = new File(protectionDomain.getCodeSource().getLocation().getFile());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment