public static URL baseUrlOfClass(Class<?> clazz) {
        try {
            String name = clazz.getName();
            URL url = clazz.getResource("/" + name.replace('.', '/') + ".class");
            int curPos = 0;
            do {
                curPos = name.indexOf('.', curPos + 1);
                if (curPos >= 0) {
                    url = new URL(url, "..");
                }
            } while (curPos >= 0);
            return url;
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException("Invalid URL for class " + clazz.getName(), e);
        }
    }