{"record":{"id":"b4ffa13ffc78d145","repo":"java-native-access/jna","slug":"native-library-resourcepath-not-found-in-resource-path-path","errorCode":null,"errorMessage":"Native library (resourcePath) not found in resource path (path)","messagePattern":"Native library \\(resourcePath\\) not found in resource path \\(path\\)","errorType":"exception","errorClass":"java.io.IOException","httpStatus":null,"severity":"error","filePath":"src/com/sun/jna/Native.java","lineNumber":1210,"sourceCode":"                // Fallback for legacy darwin behaviour: darwin was in the past\n                // special cased in that all architectures were mapped to the same\n                // prefix and it was expected, that a fat binary was present at that\n                // point, that contained all architectures.\n                if(Platform.RESOURCE_PREFIX.startsWith(\"com/sun/jna/darwin\")) {\n                    url = loader.getResource(\"com/sun/jna/darwin\" + resourcePath.substring((\"com/sun/jna/\" + Platform.RESOURCE_PREFIX).length() + 1));\n                }\n                if (url == null) {\n                    // If not found with the standard resource prefix, try without it\n                    url = loader.getResource(libname);\n                }\n            }\n        }\n        if (url == null) {\n            String path = System.getProperty(\"java.class.path\");\n            if (loader instanceof URLClassLoader) {\n                path = Arrays.asList(((URLClassLoader)loader).getURLs()).toString();\n            }\n            throw new IOException(\"Native library (\" + resourcePath + \") not found in resource path (\" + path + \")\");\n        }\n        LOG.log(DEBUG, \"Found library resource at {0}\", url);\n\n        File lib = null;\n        if (url.getProtocol().toLowerCase().equals(\"file\")) {\n            try {\n                lib = new File(new URI(url.toString()));\n            }\n            catch(URISyntaxException e) {\n                lib = new File(url.getPath());\n            }\n            LOG.log(DEBUG, \"Looking in {0}\", lib.getAbsolutePath());\n            if (!lib.exists()) {\n                throw new IOException(\"File URL \" + url + \" could not be properly decoded\");\n            }\n        }\n        else if (!Boolean.getBoolean(\"jna.nounpack\")) {\n            InputStream is = url.openStream();","sourceCodeStart":1192,"sourceCodeEnd":1228,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/src/com/sun/jna/Native.java#L1192-L1228","documentation":"extractFromResourcePath could not resolve the given native-library resource path via the supplied ClassLoader or any classpath URL, so it throws IOException 'Native library (resourcePath) not found in resource path (path)', echoing the resource being sought and the effective classpath/URLs searched. Callers like loadNativeLibrary convert this into UnsatisfiedLinkError.","triggerScenarios":"extractFromResourcePath invoked (directly or via JNA library loading) with a resourcePath that no ClassLoader on the search path can resolve - e.g. the platform-native folder is missing from all classpath entries.","commonSituations":" fat-jar assembly excluding native resources; custom URLClassLoader whose URLs omit the JAR holding the natives; typo'd or stale resource prefix; running on a platform whose prefix directory was never packaged.","solutions":["Ensure the JAR containing the resource (com/sun/jna/<prefix>/<lib>) is on the effective classpath of the loader being used","Inspect the printed resource path list in the message and add the missing classpath entry or JAR","Pass the correct ClassLoader argument to extractFromResourcePath instead of one that cannot see the resource","Pre-extract the library to the filesystem and load it by absolute path instead of from the resource path"],"exampleFix":"// before\nNative.extractFromResourcePath(\"/com/sun/jna/linux-x86/libjnidispatch.so\", limitedLoader);\n// after\nNative.extractFromResourcePath(\"/com/sun/jna/\" + Platform.RESOURCE_PREFIX + \"/libjnidispatch.\" + Platform.getNativeLibraryResourceSuffix(), Native.class.getClassLoader());","handlingStrategy":"validation","validationCode":"// ensure the resource is visible to the classloader you will use\nString res = \"/com/sun/jna/\" + com.sun.jna.Platform.RESOURCE_PREFIX + \"/libjnidispatch.so\";\nif (loader.getResource(res) == null) {\n    throw new IllegalStateException(res + \" not visible to loader \" + loader);\n}","typeGuard":null,"tryCatchPattern":"try { Native.extractFromResourcePath(res, loader); } catch (IOException e) { if (String.valueOf(e.getMessage()).startsWith(\"Native library (\") && e.getMessage().contains(\"not found in resource path\")) { throw new IllegalStateException(\"Add the JAR containing \" + res + \" to the classpath\", e); } throw e; }","preventionTips":["Pass the ClassLoader that can actually see the JNA JAR (context loader vs own loader)","Verify classpath entries in the deployment (fat jar, app server) include native folders","Prefer the official jna.jar over repackaged copies"],"tags":["java","classpath","resource-not-found","io"],"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"}