RCP应用添加JNA遇Bundle-NativeCode匹配异常求助
org.osgi.framework.BundleException: No Bundle-NativeCode match for JNA 4.5.1 in RCP Apps Hey there! I’ve wrestled with this exact JNA + RCP OSGi issue before, so let’s break down how to get past that frustrating No Bundle-NativeCode match error:
1. Double-Check Your Bundle-NativeCode Manifest Entries
OSGi is extremely picky about native code path and attribute matching. For JNA 4.5.1, your MANIFEST.MF entries should mirror the exact structure inside the JNA JARs. For Windows, it should look something like this:
Bundle-NativeCode: lib/native/win32-x86/jnidispatch.dll; osname=Win32; processor=x86,
lib/native/win32-x86-64/jnidispatch.dll; osname=Win32; processor=x86-64
- Verify the path matches exactly what’s in your
jna-4.5.1.jar(case-sensitive, even on Windows!) - Don’t miss the commas at the end of each line except the last one
- Ensure
osnameandprocessorvalues align with your target system (e.g.,Win32for all Windows versions,x86-64for 64-bit)
2. Confirm OSGi System Properties Are Correct
Your OSGi runtime needs to report the right OS and architecture to match the native code entries. In your RCP run configuration, add these VM arguments (adjust for 32-bit if needed):
-Dosgi.os=win32 -Dosgi.arch=x86_64
If you’re setting these via a config file, make sure there are no typos—even a missing underscore will break the match.
3. Use OSGi-Ready JNA Bundles (Don’t Roll Your Own)
Manual JAR-to-bundle conversions often botch the native code configuration. Instead, pull the official OSGi-compatible JNA artifacts:
net.java.dev.jna:jna:4.5.1net.java.dev.jna:jna-platform:4.5.1
These come pre-configured with the correctBundle-NativeCodeentries, so you won’t have to tweak the manifest manually.
4. Ensure JNA Bundles Are Properly Started
In your Eclipse Run Configurations > Bundles tab:
- Locate
jnaandjna-platformbundles - Check their boxes to ensure they’re included in the runtime
- Set their start level to a value that loads them before your application code (e.g., level 4, same as most third-party bundles)
5. Clean and Rebuild Your Workspace
Old cached build files or manifest data can cause false matching errors. Do a full clean:
- Go to
Project > Cleanin Eclipse - Select your RCP project and click
OK - Rebuild the project and re-run your RCP application
6. Enable OSGi Debug Logging for Native Code
If you’re still stuck, enable debug logging to see exactly why the match is failing. Add this VM argument:
-Dosgi.debug=debug.options
Then create a debug.options file with this line:
org.osgi.framework/nativecode = debug
The logs will show you which OS/architecture values the runtime is using, and which native code entries it’s checking—this will point straight to the mismatch.
内容的提问来源于stack exchange,提问作者nahzor

