{"record":{"id":"06c4f39a81f58a39","repo":"java-native-access/jna","slug":"could-not-find-jna-native-support","errorCode":null,"errorMessage":"Could not find JNA native support","messagePattern":"Could not find JNA native support","errorType":"exception","errorClass":"java.lang.UnsatisfiedLinkError","httpStatus":null,"severity":"critical","filePath":"src/com/sun/jna/Native.java","lineNumber":1105,"sourceCode":"    }\n\n    static final String JNA_TMPLIB_PREFIX = \"jna\";\n    /**\n     * Attempts to load the native library resource from the filesystem,\n     * extracting the JNA stub library from jna.jar if not already available.\n     */\n    private static void loadNativeDispatchLibraryFromClasspath() {\n        try {\n            String mappedName = System.mapLibraryName(\"jnidispatch\").replace(\".dylib\", \".jnilib\");\n            if(Platform.isAIX()) {\n                // OpenJDK is reported to map to .so -- this works around the\n                // difference between J9 and OpenJDK\n                mappedName = \"libjnidispatch.a\";\n            }\n            String libName = \"/com/sun/jna/\" + Platform.RESOURCE_PREFIX + \"/\" + mappedName;\n            File lib = extractFromResourcePath(libName, Native.class.getClassLoader());\n            if (lib == null) {\n                throw new UnsatisfiedLinkError(\"Could not find JNA native support\");\n            }\n\n            LOG.log(DEBUG_JNA_LOAD_LEVEL, \"Trying {0}\", lib.getAbsolutePath());\n            System.setProperty(\"jnidispatch.path\", lib.getAbsolutePath());\n            System.load(lib.getAbsolutePath());\n            jnidispatchPath = lib.getAbsolutePath();\n            LOG.log(DEBUG_JNA_LOAD_LEVEL, \"Found jnidispatch at {0}\", jnidispatchPath);\n\n            // Attempt to delete immediately once jnidispatch is successfully\n            // loaded.  This avoids the complexity of trying to do so on \"exit\",\n            // which point can vary under different circumstances (native\n            // compilation, dynamically loaded modules, normal application, etc).\n            if (isUnpacked(lib)\n                && !Boolean.getBoolean(\"jnidispatch.preserve\")) {\n                deleteLibrary(lib);\n            }\n        }\n        catch(IOException e) {","sourceCodeStart":1087,"sourceCodeEnd":1123,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/src/com/sun/jna/Native.java#L1087-L1123","documentation":"After failing to load the native dispatch library from OS paths, JNA tries to extract /com/sun/jna/<RESOURCE_PREFIX>/libjnidispatch.* from the resource path. When extractFromResourcePath returns null - the resource is absent from the classpath - JNA throws this UnsatisfiedLinkError, meaning the JAR on the classpath lacks the native binaries for the current platform.","triggerScenarios":"Loading any JNA-based library when the classpath contains a jna.jar without native resources for Platform.RESOURCE_PREFIX (e.g. linux-x86-64), or a repackaged/minimized JAR stripped of .so/.dll/.dylib files.","commonSituations":"Using a 'slim' or shaded JAR that dropped native resources; mixing an old jna.jar with a newer jnidispatch; running an uncommon platform (e.g. linux-aarch64) with a JAR built without that prefix; application-server classloader not exposing the resource.","solutions":["Replace the classpath JAR with the official full jna.jar matching (or exceeding) your JNA version so it includes natives for your platform prefix","Verify the resource exists: the JAR must contain com/sun/jna/<Platform.RESOURCE_PREFIX>/libjnidispatch.*","Pre-install the native library and set -Djna.boot.library.path to its directory as a fallback","Log Platform.RESOURCE_PREFIX and the classpath to confirm the expected prefix and JAR are actually used by the effective classloader"],"exampleFix":"// before (minimized jar missing natives)\n<artifactItem><artifactId>jna</artifactId><excludes>com/sun/jna/**</excludes></artifactItem>\n// after\n<dependency><groupId>net.java.dev.jna</groupId><artifactId>jna</artifactId><version>5.x</version></dependency>","handlingStrategy":"fallback","validationCode":"// verify the native resource exists before first JNA call\nString prefix = com.sun.jna.Platform.RESOURCE_PREFIX;\nString res = \"/com/sun/jna/\" + prefix + \"/\" + (com.sun.jna.Platform.isWindows() ? \"jnidispatch.dll\" : \"libjnidispatch.so\");\nif (Native.class.getResourceAsStream(res) == null) {\n    throw new IllegalStateException(\"jnidispatch resource missing for prefix \" + prefix + \" - replace jna.jar\");\n}","typeGuard":null,"tryCatchPattern":"try { Native.load(\"c\", CLibrary.class); } catch (UnsatisfiedLinkError e) { if (String.valueOf(e.getMessage()).contains(\"Could not find JNA native support\")) { throw new IllegalStateException(\"Classpath jna.jar lacks natives for \" + com.sun.jna.Platform.RESOURCE_PREFIX, e); } throw e; }","preventionTips":["Never shade/minimize away com/sun/jna native resource directories","Include natives for all target platform prefixes or use an OS-specific classifier JAR","Log Platform.RESOURCE_PREFIX at startup to catch platform mismatches early"],"tags":["java","native-library","classpath","resource-not-found"],"backgroundTag":"resource-not-found","analyzedSha":"d036ad9781adad4b66693e8fa7098e4ac665e0a3","analyzedAt":"2026-09-12T06:50:59.239Z","contentChangedAt":"2026-09-12T06:50:59.239Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}