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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:19:05+00:00 2026-06-07T18:19:05+00:00

In my library’s code, I load class names from an XML file using JAXB,

  • 0

In my library’s code, I load class names from an XML file using JAXB, in order to instanciate them later on using Class.forName(). A fictive example to illustrate the case:

public void libraryMethod() throws Exception {
  List<String> classNames = loadClassNamesFromXML();

  for (String className : classNames) {
    Class.forName(className).newInstance().doThings();
  }
}

Now, some users use OSGi to configure their applications, and they load my library with a different class loader than the classes they configure using my XML structure. This means that loading may fail, as the class cannot be found.

Is there any more reliable way to load such classes? Or is there any other way to configure these instances? I’m open to suggestions that result in this:

public void libraryMethod() throws Exception {
  // Spring does things like this:
  List<SomeType> instances = loadInstancesFromXML();

  for (SomeType instance : instances) {
    instance.doThings();
  }
}

Some constraints:

  • From a library perspective, the lifecycle of those instances is unimportant. If they have (user) state, my library would not notice.
  • I want to keep things simple in this library, so I want to avoid creating external dependencies on configuration frameworks like spring, for instance. So I’m only interested in solutions that can be achieved with standard JDK 6+ distributions.
  • I would really like to keep my simple XML configuration file (slight adaptations to the XML structure are OK).
  • 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-07T18:19:08+00:00Added an answer on June 7, 2026 at 6:19 pm

    If you want your library to be flexible and work in both OSGi and non-OSGi environment, you should allow users provide their own ClassLoader’s or let them tell your library which class names they have. Read Neil Bartlett blog post.

    Original link returns a 404. You can access the article on the Wayback Machine.

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

Sidebar

Related Questions

In my CGI library, I'm using a converter in order to convert from a
The library I'm using has class G and class S which inherits G. I
Jsf library (that is included in WEB-INF/lib) might contain its own faces-config.xml file. Is
A library that my java application uses needs looks for a file (log4j.xml) in
----------Class library file where i am calling WCF service------------- public class AllEmployeeViewModel { //
Simple library is great and i already parsed many different XML from soap servers
What library to use to write XML file in a C++ program? I've found
library(ggplot2) This code produces a nice looking plot: qplot(cty, hwy, data = mpg, colour
/System/Library/Services/ImageCaptureService.app - what is it? Evernote uses it for importing the images from scanners
What library should I use to connect to odbc from python on windows? Is

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.