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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:34:13+00:00 2026-05-14T02:34:13+00:00

I’m trying to develop a web application that is going to be launched from

  • 0

I’m trying to develop a web application that is going to be launched from a HTTP OSGi service, this application needs to use other OSGi service (db4o OSGi), for what I need a reference to a BundleContext. I have tried two different approaches to get the OSGi context in the web application:

  1. Store the BundleContext of the Activator in a static field of a class that the web service can import and use.
  2. Use FrameworkUtil.getBundle(this.getClass()).getBundleContext() (being this an instance of MainPage, a class of the web application).

I think that first option is completely wrong, but anyway I’m having problems with the class loaders in both options. In the second one it raises a LinkageError:

java.lang.LinkageError: loader constraint violation: loader (instance of org/apache/felix/framework/ModuleImpl$ModuleClassLoader) previously initiated loading for a different type with name "com/db4o/ObjectContainer"

Also tried with Equinox and I have a similar error:

java.lang.LinkageError: loader constraint violation: loader (instance of org/eclipse/osgi/internal/baseadaptor/DefaultClassLoader) previously initiated loading for a different type with name "com/db4o/ObjectContainer"

The code that provokes the exception is:

ServiceReference reference = context.getServiceReference(Db4oService.class.getName());
Db4oService service = (Db4oService)context.getService(reference);
database = service.openFile("foo.db");

The exception is raised in the last line, database class is ObjectContainer, if I change the type of this variable to Object the exception is not raised, but it’s not useful as an Object 🙂

Update: I have tried to use other services instead of db4o and they worked as expected. Maybe db4o OSGi bundle does something strange when loading its own classes, or maybe I’m not using it correctly. It also works if I use it from a non-web bundle.

  • 1 1 Answer
  • 1 View
  • 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-05-14T02:34:13+00:00Added an answer on May 14, 2026 at 2:34 am

    Why not passing the BundleContext in the constructor of the servlet class? That class can safely store the context since the service is stopped when the bundle is stopped (and the BundleContext becomes invalid).

    I recommend to avoid using classloaders in OSGi at all, since a) the OSGi framework does a lot of classloader magic in order to separate the bundles from each others, and b) you might run in a lot of problems when OSGi and Java 2 security is enabled. This will most probably reduce the reusability of your bundle.

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

Sidebar

Ask A Question

Stats

  • Questions 380k
  • Answers 380k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer #myDiv { margin: 0 auto; } May 14, 2026 at 9:53 pm
  • Editorial Team
    Editorial Team added an answer In this release, all the types must be in the… May 14, 2026 at 9:53 pm
  • Editorial Team
    Editorial Team added an answer I like TypeT's answer but it may help to know… May 14, 2026 at 9:53 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.