public static Class<?> loadClass(String pathToJar, String targetClassName) throws Exception {
        JarFile jarFile = new JarFile(pathToJar);
        Enumeration e = jarFile.entries();

        URL[] urls = { new URL("jar:file:" + pathToJar+"!/") };
        ClassLoader cl = URLClassLoader.newInstance(urls);

        Class target = null;

        while (e.hasMoreElements()) {
            JarEntry je = (JarEntry) e.nextElement();
            if(je.isDirectory() || !je.getName().endsWith(".class")){
                continue;
            }
            // -6 because of .class
            String className = je.getName().substring(0,je.getName().length()-6);
            className = className.replace('/', '.');
            Class clazz = cl.loadClass(className);

            if(className.equals(targetClassName)){
                target = clazz;
            }
        }

        return target;
	}