Tags

http://sacharya.com/find-the-jar-file-given-a-class-name/

Found this quite useful to get the jar name from within your main class.
Basic concept is to getResource then replace the “/” and “!” accordingly.

public static String findPathJar(Class context) throws IllegalStateException {
   URL location = context.getResource('/' + context.getName().replace(".", "/")
      + ".class");
   String jarPath = location.getPath();
   return jarPath.substring("file:".length(), jarPath.lastIndexOf("!"));
}
Advertisements