Odd Issue With java.lang.RuntimeException: No resource
<p>When I run my project in NetBeans, it runs fine, but when I try to run it after exporting it, I got this exception:
<code>java.lang.RuntimeException: No resource for micro/main/plugins</code> when trying to load modules. Like I said everything works fine in Netbeans, but not after exported.</p>

<p>When I unpack the .jar, and the files and folder do indeed exist. I'm beyond stumped.</p>

<p>This is the code I am using to get all of the classes:</p>

<pre><code>private static ArrayList&lt;Class&lt;?&gt;&gt; getClassesForPackage(Package pkg) {
    String pkgname = pkg.getName();
    ArrayList&lt;Class&lt;?&gt;&gt; classes = new ArrayList&lt;Class&lt;?&gt;&gt;();

    File directory = null;
    String fullPath;
    String relPath = pkgname.replace('.', '/');
    URL resource = ClassLoader.getSystemClassLoader().getResource(relPath);
    if (resource == null) {
        throw new RuntimeException("No resource for " + relPath);
    }
    fullPath = resource.getFile();

    try {
        directory = new File(resource.toURI());
    } catch (URISyntaxException e) {
        throw new RuntimeException("", e);
    } catch (IllegalArgumentException e) {
        directory = null;
    }

    if (directory != null &amp;&amp; directory.exists()) {
        String[] files = directory.list();
        for (int i = 0; i &lt; files.length; i++) {
            if (files[i].endsWith(".class")) {
                String className = pkgname + '.' + files[i].substring(0, files[i].length() - 6);
                try {
                    classes.add(Class.forName(className));
                } catch (ClassNotFoundException e) {
                    throw new RuntimeException("ClassNotFoundException loading " + className);
                }
            }
        }
    } else {
        try {
            String jarPath = fullPath.replaceFirst("[.]jar[!].*", ".jar").replaceFirst("file:", "");
            JarFile jarFile = new JarFile(jarPath);
            Enumeration&lt;JarEntry&gt; entries = jarFile.entries();
            while (entries.hasMoreElements()) {
                JarEntry entry = entries.nextElement();
                String entryName = entry.getName();
                if (entryName.startsWith(relPath) &amp;&amp; entryName.length() &gt; (relPath.length() + "/".length())) {
                    String className = entryName.replace('/', '.').replace('\\', '.').replace(".class", "");
                    try {
                        classes.add(Class.forName(className));
                    } catch (ClassNotFoundException e) {
                        throw new RuntimeException("ClassNotFoundException loading " + className);
                    }
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(pkgname + " (" + directory + ") does not appear to be a valid package", e);
        }
    }
    return classes;
}
</code></pre>

<p>Code it fails on:</p>

<pre><code>            for(Class c : getClasses(Commands.class.getPackage())){//This line
            if(c.getSuperclass().equals(Commands.class)){
                try {
                    c.newInstance();
                } catch (InstantiationException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
</code></pre>
