How do you find the JAR filename from the running code
I want to be able to load files from an executable JAR file, the best method I have is below. But it requires knowing a class in the JAR which is not a problem. I just want to know if it can be done without knowing a class file in the JAR so I can get rid of the anyfileinjar parameter below.
Thanks
public String getJARPath(String anyfileinjar){
int idx;
String ret = getClass().getResource(anyfileinjar).getPath();
if (ret.startsWith("file:/")){
ret = ret.substring(6);
}
idx = ret.indexOf('!');
if (idx != -1){
ret = ret.substring(0, idx);
}
return ret;
}

