Java Reflection Not Working (Running .jar)
<p>I'm trying to make a program to delete itself, but having some trouble.
The jar I'm building works fine, I cant run it in my program though.</p>

<p>This is the error:</p>

<pre><code>java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at jar.Compile.buildDelete(Compile.java:43)
</code></pre>

<p>Code I'm using:</p>

<pre><code>CodeSource codeSource = jars.delete.Main.class.getProtectionDomain().getCodeSource();
File jarfile = new File(codeSource.getLocation().toURI().getPath());
filepath = jarfile.getParentFile().getPath() + "test.jar";
build(System.getProperty("user.home") + File.separator + "delete.jar");
String classname = "jars.delete.Main";

File jar = new File(System.getProperty("user.home") + File.separator + "delete.jar");
URLClassLoader classLoader = new URLClassLoader(new URL[]{jar.toURI().toURL(), null});
JarFile jarFile = new JarFile(jar);
Class&lt;?&gt; clazz = classLoader.loadClass(classname);
Method main = clazz.getMethod("main", String[].class);
main.invoke(null, new Object[]{new String[]{}});
</code></pre>

<p>I was not having any troubles with this before, it's quite odd.</p>
