Note that there are some explanatory texts on larger screens.

plurals
  1. POJava Annotations don't work with external Jar Files
    text
    copied!<p>So, I'm currently working on a plugin system (plugins are jar files located in a plugins folder) for my command line "operating system". Works fine but the API doesn't.</p> <p>I am using Annotations to get the Plugin main class and the event classes. However, it doesn't seem to find my Annotations.</p> <p>This is what I use to load my plugins:</p> <pre><code>public static void loadPlugin(File file) { try { URL urlList[] = { new File("plugins/" + file.getName()).toURI().toURL() }; URLClassLoader classLoader = new URLClassLoader(urlList); Class&lt;?&gt; pluginclass, eventclass = pluginclass = null; String name, version = name = null; Priority priority = Priority.NORMAL; String[] classes = Utils.getJarClasses(file, "plugin").toArray(new String[] {}); for (String s : classes) { System.out.println(s); Class&lt;?&gt; c = classLoader.loadClass(s); Plugin p = c.getAnnotation(Plugin.class); EventHandler e = c.getAnnotation(EventHandler.class); if (p != null) { System.out.println("not null!"); pluginclass = c; name = p.name(); version = p.version(); priority = p.priority(); } if (e != null) { eventclass = c; } } switch (priority) { case NORMAL: plugins.add(new Class&lt;?&gt;[] { pluginclass, eventclass }); case DEVELOPER_API: apis.add(new Class&lt;?&gt;[] { pluginclass, eventclass }); } print("Loaded Plugin: " + name + " V" + version + " with priority " + priority.toString() + "."); } catch (Exception e) { e.printStackTrace(); } } </code></pre> <p>It's printing out the class it's currently looping through just fine, but <strong>p</strong> and <strong>e</strong> are always null, no matter what. <strong>version</strong> and <strong>name</strong> are always null, too, obviously.</p> <p>My Annotation classes have got <code>@Retention(RetentionPolicy.RUNTIME)</code>, that's the main reason why I'm asking here.</p> <p>I have tested a similar system, just that one didn't use jar files (classes inside of a package, instead) and worked fine.</p> <p>Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload