Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7965051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:03:13+00:00 2026-06-04T06:03:13+00:00

I am trying to develop a plugin system, which provides a interface to load

  • 0

I am trying to develop a plugin system, which provides a interface to load jar at runtime. Each jar contains a class that extends from a common abstract class. For example:

//BasicPlugin.java
package byv;

abstract class BasicPlugin {
    abstract public int test(int a);
}

I implemented a subclass:

//PluginA.java
package byv;

import byv.BasicPlugin;

public class PluginA extends BasicPlugin {
    @Override
    public int test(int a) {
        return a + a;
    }
}

The subclass above was compiled and packaged into a jar file(PluginA.jar). This jar only contains PluginA.class. And then in the main project I load it using URLClassLoader:

private static void loadTest() throws Exception {
    URL url = new File("PluginA.jar").toURI().toURL();
    URLClassLoader ClassLoader = URLClassLoader.newInstance(new URL[] {url});

    Class<?> clazz = Class.forName("byv.PluginA", true, ClassLoader);

    BasicPlugin obj = (BasicPlugin) clazz.newInstance();
    obj.test(2);
}

I have already added a reference to BasicPlugin in the main project. But errors still occured:

Exception in thread "main" java.lang.IllegalAccessError: class byv.PluginA cannot access its superclass byv.BasicPlugin
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:615)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at byv.Main.loadTest1(Main.java:18)
    at byv.Main.main(Main.java:11)

So how can I fix this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:03:14+00:00Added an answer on June 4, 2026 at 6:03 am

    Since it is an IllegalAccessError I suggest you make BasicPlugin public to solve the problem. As far as I know the class you defined is package protected. As such it is not accessible from a different class loader. Since that is what you require for your plugin, it makes not sense to make the class anything else than public.

    One more thing, URLClassLoader has a second constructor in which you can specify the parent loader. This loader is then used to load the plugin class. In a more complex environment you may want to specify that loader. Currently your code uses more or less the system loader, which is ok in your example, but I don’t know what you intend to do later on. BasicPlugin.class.getClassLoader() gives you the right loader for that class for sure.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to develop a small plugin that will do a sort-of auto-completion along
I'm trying to develop a class that supports an asynchronus method invocation. This is
I am trying to develop a firefox plugin, which should be executed, whenever a
I'm trying to develop a plugin that shows website screenshot, when a user clicks
I'm trying to develop a plugin that takes a callback as the first argument
I'm trying to develop a plugin for Eclipse that will allow me to modify
intro Hello, I'm trying to develop some plugin or / and object in javascript,
I am trying develop a basic referrer system to my Django website, system will
im trying to develop an app for a win CE mobile device that downloads
I am trying to develop an XSLT stylesheet which will transform an xml into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.