java get jar path
//this worked for me
File jarDir = new File(ClassLoader.getSystemClassLoader().getResource(".").toURI());
//this didn't work for me but it is often suggested
File jar = new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation().toURI());
4.4
5
return new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation()
.toURI()).getPath();
Thank you!
5
0
Are there any code examples left?
New code examples in category Java