class PathsClassLoader extends ClassLoader {

    @Override
    protected Class findClass(String name) throws ClassNotFoundException
    {
        Class found = null;
        for (String aPath : classpath)
        {
            String bodyPath = name.replace('.', '/');
            File pathFile = new File(aPath);
            if (pathFile.isDirectory())
            {
                byte[] body;
                int bodySize;
                File bodyFile = new File(pathFile, bodyPath + ".class");
                if (!bodyFile.exists())
                {
                    continue;
                }
                bodySize = (int) bodyFile.length();
                body = new byte[bodySize];
                FileInputStream bodyStream = null;
                try
                {
                    bodyStream = new FileInputStream(bodyFile);
                    int pos = 0;
                    int len;
                    do
                    {
                        len = bodyStream.read(body, pos, bodySize);
                        pos += len;
                    } while (pos < bodySize);
                } catch (IOException e)
                {
                    throw new ClassNotFoundException("Class body not read", e);
                } finally
                {
                    if (null != bodyStream)
                    {
                        try
                        {
                            bodyStream.close();
                        } catch (IOException ex)
                        {
                            /* don't care */
                        }
                    }
                }
                found = defineClass(name, body, 0, bodySize);
                break;
            }
            else if (pathFile.isFile())
            {
                byte[] body;
                int bodySize;
                InputStream bodyStream = null;
                JarFile jar = null;
                try
                {
                    jar = new JarFile(pathFile);
                    JarEntry entry = jar.getJarEntry(bodyPath + ".class");
                    if (null == entry)
                    {
                        continue;
                    }
                    bodyStream = jar.getInputStream(entry);
                    bodySize = (int) entry.getSize();
                    body = new byte[bodySize];
                    int pos = 0;
                    int len;
                    do
                    {
                        len = bodyStream.read(body, pos, bodySize);
                        pos += len;
                    } while (pos < bodySize);
                } catch (IOException e)
                {
                    throw new ClassNotFoundException("Class body not read", e);
                } finally
                {
                    if (null != bodyStream)
                    {
                        try
                        {
                            bodyStream.close();
                        } catch (IOException e)
                        {
                            /* don't care */
                        }
                    }
                    if (null != jar)
                    {
                        try
                        {
                            jar.close();
                        } catch (IOException e)
                        {
                            /* don't care */
                        }
                    }
                }
                found = defineClass(name, body, 0, bodySize);
                break;
            }
            else
            {
                // Just skip this path element -- probably just file not found here.
            }
        }
        if (null == found)
        {
            throw new ClassNotFoundException(name);
        }
        else
        {
            resolveClass(found);
            return found;
        }
    }

      PathsClassLoader(ClassLoader parent, String[] classpath);

}