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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:32:29+00:00 2026-05-12T12:32:29+00:00

OSGi cannot find my DLL file, and I can’t seem to figure out why.

  • 0

OSGi cannot find my DLL file, and I can’t seem to figure out why.

Currently I have the DLL file (foo.dll) at the root of my bundle, I’ve also tried having it in a libs directory.

The Manifest for the bundle in question looks something like this:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: foobundle
Bundle-SymbolicName: com.foo.bar
Bundle-Version: 1.0.0
Bundle-Vendor: me
Import-Package: com.sun.jna,
 com.sun.jna.ptr,
 com.sun.jna.win32
Export-Package: com.foo.bar
Bundle-NativeCode: foo.dll;
 osname=WindowsXP;
 processor=x86

Then in my JNA interface I perform a loadLibrary (as per the documentation):

public interface MyFooInterface extends com.sun.jna.Library{
    static final MyFooInterface INSTANCE = (MyFooInterface)com.sun.jna.Native.loadLibrary("foo", MyFooInterface .class);

    // specific interface defs here...
}

Then in another class I attempt to use the JNA interface

// ...code
int var = MyFooInterface.INSTANCE.bar();
// ...more code

I have JNA supplied via another bundle (which exports com.sun.jna and the other packages imported above), but have also tried packaging it with the bundle defined here (and added it to the classpath in that case, etc.).

I’ve also tried specifying Bundle-NativeCode: /foo.dll.

Also of interest, these are the relevant OSGi properties (which I pulled up using getprop)

org.osgi.framework.os.name=WindowsXP
org.osgi.framework.processor=x86

Even after all this (and with every trial I made) I always end up with the following error (and a stack trace not shown):

java.lang.UnsatisfiedLinkError: Unable to load library 'foo': The specified module could not be found.

…so what am I missing?

Edit: I should also note that I’ve tested and had success the JNA interface code and the DLL that it talks to as part of a JUnit Test program.

Edit 2: Adding this code to the class that’s calling the library seems to allow JNA to find the library (when Native.loadLibrary gets called later). It seems I should be able to avoid this call based on the Bundle-NativeCode directive in the Manifest. Clearly once the library is loaded Native.loadLibrary grabs the existing instance of it, but I’d prefer not to depend on this very order-specific tactic.

static{
    System.loadLibrary("foo");
}
  • 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-12T12:32:29+00:00Added an answer on May 12, 2026 at 12:32 pm

    The problem is the specialised JNA loadLibrary call, which is not OSGi aware. When you invoke loadLibrary from an OSGi bundle, it will use the OSGi classloader (which is bundle aware) to find where the DLL is, and in this case, extract it out from the bundle and make it loadable via the System.loadLibrary() call against a specific location.

    Since this JNA seems to be (a) not OSGi aware, and (b) superflous, why not just use System.loadLibrary() instead?

    If you need to write both, then perform a System.loadLibrary() in the bundle’s start() method in the BundleActivator, which will bring the native library in (you probably want to ensure that if it can’t be loaded, the bundle can’t be started in any case).

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

Sidebar

Related Questions

I want to implement OSGI bundle with JSF pages - WAB file, which can
I want to implement OSGI bundle which can write error messages into log file.
I have config.properties in my OSGi bundle. but the OSGi bundle can not read
I'm tracking OSGi bundles like this: BundleTracker<Foo> bundleTracker = new BundleTracker<>(context, Bundle.ACTIVE, new BundleTrackerCustomizer<Foo>(){
I've got a org.osgi.framework.Bundle instance, and I tried bundle.getLocation(); bundle.getClass().getProtectionDomain().getCodeSource().getLocation(); none of them can
I am using the aQute Bnd toolset to create an OSGi bundle and have
I have created an OSGi bundle with an exposed (declarative) service. If I, when
I have an OSGi bundle which is deployed into Apache Karaf 2.2.8 . In
I have written this OSGI bundle: /* * To change this template, choose Tools
I am new to OSGI and I am trying to figure out how I

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.