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 8984313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:04:24+00:00 2026-06-15T21:04:24+00:00

I want to make an application that can dynamically load plug-ins but I’ve not

  • 0

I want to make an application that can dynamically load plug-ins but I’ve not found any literature on Internet.

The difficult thing is: I don’t know the name in advance.

For example I’ve a Plugin interface:

public interface Plugin {
    public static Plugin newPlugin();
    public void executePlugin(String args[]);
}

So that every Class implementing Plugin in the jar file are instantiated in a list:

Method method = classToLoad.getMethod ("newPlugin");
mylist.add(method.invoke(null);
  1. First problem is, I cannot have a static method in an interface.
  2. Second problem is, I don’t know how to find all classes that implement an interface

Thanks for your help.

  • 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-15T21:04:25+00:00Added an answer on June 15, 2026 at 9:04 pm

    So it seems like you want to dynamically discover Classes that implement a specific interface (e.g., Plugin) at runtime. You have basically two choices for this:

    1. Use a component framework like osgi
    2. Use Java’s internal discovery process (ServiceLoader)

    Since there are many good tutorials on osgi (also small ones), I will not detail that here. To use Java’s internal discovery process, you need to do the following:

    • Bundle all “new” classes that you wish to discover into a jar file
    • Create a new file inside the jar file: META-INF/services/package.Plugin You must use the full package qualifier here
    • This file is a simple text file and contains the fully qualified name of each class implementing Plugin in that jar-file
    • Place that jar file into the classpath of your (potentially already running) application
    • Discover the services:

    Service discovery is done like this:

    ServiceLoader<Plugin> loader = ServiceLoader.load(Plugin.class)
    for (Plugin p : loader) {
        // do something with the plugin
    }
    

    There are more details here: http://docs.oracle.com/javase/7/docs/api/java/util/ServiceLoader.html

    As for static methods in interfaces: not possible. The semantics of that would also be somewhat weird as static methods are accessible without an instance of a class, and interfaces just define the methods, without any functionality. Thus, static would allow to call Interface.doSomething() whereas the interface does not define any functionality, this leads just to confusion.

    edit:

    added description what should be in the meta-file

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

Sidebar

Related Questions

I just want to know that can i make an application which have some
I want to make an application that can generate point to point gradient (like
I want to make a desktop application that can read the SMS from the
I want to make an application that can split an mp3 into pieces. Ex:
So, I want to make an application that can read in several groups of
I want to make an application that can send an SMS to person in
HI, Im using Delphi and I want to make an application that can do
I want to make a MFC Application that can only run form a know
I want to make an application that would display a message when a user
I want to make an Application that uses RxTx version 2.2pre2 to work with

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.