Rob Prime wrote: In short, you can't get this path directly, but there are some tricks. One uses ProtectionDomain (do a search on Javaworld.com), one uses Class.getResource() using the class itself. For example, in class Test:
Thank you, Rob, yes, they both work.
I found this on Real Gagnon's site this morning demonstrating getProtectionDomain as you said:
http://www.rgagnon.com/javadetails/java-0581.html
URL url = getClass().getProtectionDomain().getCodeSource().getLocation();
getProtectionDomain() will throw a security exception however if the security manager doesn't allow it.