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

  • Home
  • SEARCH
  • 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 8256077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:44:15+00:00 2026-06-08T01:44:15+00:00

I tried implementing my own class loader based on some examples. However, I think

  • 0

I tried implementing my own class loader based on some examples. However, I think it is not working as expected ( unable to reload Jar file etc. I see few references of recommending using OSGI or Apache Felix for handling Jar file loading. Is there any examples of loading Jar, instancing a class from the Jar?

More details on what I am trying to accomplish..I have a Java command line application that essentially continuously runs. I want it to be able to reference JAR files dynamically at runtime and at run-time instance a class in these jars. These jars may contain 1 or more supporting classes. These Jars are essentially customized work units that get executed by certain event conditions from the main application that is continuously running. .. Since this is a multi-client, I wanted to have the jars be a pluginable type work units.

My current direction has been providing the ‘client’ an interface to code to and then having them package their classes in a jar file. The application will then execute the configured ( database ) jar path and run class from the Jar. This works with loading of a jar and class however, I want to be able to essentially hot deploy these jars.

In summary I would like to have a JAR file that contains classes to support a function. A defined class that will be referenced at run-time from the Jar ( from the main looping application ). The ability to change out JAR files while the main application is running.

If I am to use a third party library, it is preferred that I use Apache Felix.

thanks

I think I figured it out using Apache Felix 4. Is this the best way to load jars/classes ? Or is there a better more efficient way. My research so far did not point to one solution. thanks.

    FrameworkFactory ff = new FrameworkFactory ();
     Map<String,Object> config = new HashMap<String,Object>();
      config.put("org.osgi.framework.storage", "c:\\temp\\myclientBundles");
       config.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
   "packages needed,more packages needed");
  config.put(Constants.FRAMEWORK_STORAGE_CLEAN, "true");

  Framework fwk = ff.newFramework(config);
  fwk.start();


  BundleContext bc = fwk.getBundleContext();

  Bundle bundle =   bc.installBundle("file:C:\\my_client.jar");


      bundle.start();
      bundle.update();
      Class clazz = bundle.loadClass("client.work.process");
      Job pc = (Job) clazz.newInstance();
      pc.startWork(someConfigObject);
      bundle.stop();
      fwk.stop();
  • 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-08T01:44:18+00:00Added an answer on June 8, 2026 at 1:44 am

    If Now, simple said, I refuse to believe your problem is loading a class … 🙂 I think you have quite another problem that you think can be solved to load a class?

    In the majority of cases where people naively start loading classes the problem is extensibility. They have a system and want to selectively extend it with new functionality, I am making the assumption that you have a similar problem since you want to update the provider jar?

    If so, download bndtools and look at OSGi services, they usually fit the bill very well

    Ok, after your update. If I understand you well, you would be very well served with Apache Felix and Apache Felix File Install. File Install watches a directory and installs any bundle in that directory in the framework. Removing that jar from the directory, uninstalls the bundle. (I wrote the archetype of File Install over 12 years ago!)

    For you main JAR, make it look like:

    @Component(immediate=true)
    public void Main {  
        @Reference
        void setClient( Client client) { ... } // called whenever a client gets started
    }
    

    For each client JAR:

    @Component
    public void ClientImpl implements Client {
      ... whatever
    }
    

    This is virtually all you have to write when you use bndtools. Just create a component project, add a Bundle Descriptor for the main code and any number of descriptors for the client code examples, then Run As -> OSGi Run. You can then download Apache Felix File Install, add this to the run tab, and create some other projecs, drop the jars (continuously made in the generated folder) into the file install folder … voila. Does not get much simpler than this 🙂

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

Sidebar

Related Questions

I am implementing my own linked list in Java. The node class merely has
I'm currently working on implementing my own Trie in Scala (for learning/hobby purposes), and
I have just tried implementing a class where numerous length/count properties, etc. are uint
For a videogame I'm implementing in my spare time, I've tried implementing my own
I tried implementing dragging on android in 2 ways: Canvas with on draw. Relative
I tried implementing a sorting program in mapreduce such that I have just the
I've tried implementing this example , but the progress never displays. My page doesn't
UPDATE: I tried implementing the method specified by Peter and am getting incorrect shadowing.
UPDATE: I also tried implementing UITextViewDelegate delegate and then doing in my controller: -
Following on from: Scala classOf for type parameter I've tried implementing it but seem

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.