private File findSource(Class<?> sourceClass) { try { ProtectionDomain domain = (sourceClass != null) ? sourceClass.getProtectionDomain() : null; CodeSource codeSource = (domain != null) ? domain.getCodeSource() : null; URL location = (codeSource != null) ? codeSource.getLocation() : null; File source = (location != null) ? findSource(location) : null; if (source != null && source.exists() && !isUnitTest()) { return source.getAbsoluteFile(); } return null; } catch (Exception ex) { return null; } }