Posted By

resurge on 12/14/08


java folder active jar

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Get active execution location

 / Published in: Java


The returned file will either contain the folder from where your program is running or the executable jar file, if your program is an executable jar.

I'm using Main.class because this code is in my main method (which is in the class 'Main'). You can replace Main.class by getClass() if you want to use this code in a non-static method.

  1. try {
  2. File jarFile = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI());
  3. } catch (URISyntaxException e) {
  4. //do some error handling here
  5. }

Report this snippet  

You need to login to post a comment.