CommonPaths { public static final File getApplicationDirectory(Class clazz) { File path = null; try { path = new File(clazz.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()); if (path.exists()) { if (path.isFile()) { return path.getParentFile(); } else { return path.getParentFile().getParentFile(); } } } catch (URISyntaxException e) { e.printStackTrace(); } return path; }  static final File getApplicationDirectory(Class clazz);  }
@Test public void testGetApplicationDirectory() throws Exception { File file = CommonPaths.getApplicationDirectory(this.getClass()); assert file.isDirectory(); }