I can now use clazz.getClassLoader (). getResource (class.getName ()), then tweak the url to get the location of the jar file, but I really want to know if there is a better way to do this.
Is there an API for this? thanks.
If your class is called Foo
URL classLocation = Foo.class.getProtectionDomain().getCodeSource().getLocation()
classLocation will contain the URL from which the class was loaded. Either the folder for a separate class, or jar / zip.
Source: https://habr.com/ru/post/1299926/More articles:Find if node has siblings using simplexml - xmlC #, validation is correct - c #How to sketch using system libraries on Linux - linuxHow to automatically synchronize tables in different databases - sql-serverSymbol "|" in sms - javaFast way to get html url of content using Qt? - c ++Printing a WPF Window on One Page - PrintingHow to determine if a driver is a flexible or removable flash drive in C ++? - c ++If User.IsInRole with a string array? - c #Intelligent agents "tutorial" - artificial-intelligenceAll Articles