{"record":{"id":"769fe04707283517","repo":"alibaba/spring-ai-alibaba","slug":"could-not-find-lib-directory-in-resources","errorCode":null,"errorMessage":"Could not find lib directory in resources","messagePattern":"Could not find lib directory in resources","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/utils/FileUtils.java","lineNumber":79,"sourceCode":"\t\t\tFiles.deleteIfExists(filepath);\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\t/**\n\t * Copies all JAR files from the resources/lib directory to the specified working\n\t * directory.\n\t * @param workDir The target working directory where the JAR files will be copied.\n\t */\n\tpublic static void copyResourceJarToWorkDir(String workDir) {\n\t\ttry {\n\t\t\t// Get the JAR files from resources/lib directory\n\t\t\tClassLoader classLoader = FileUtils.class.getClassLoader();\n\t\t\tURL libUrl = classLoader.getResource(\"lib\");\n\t\t\tif (libUrl == null) {\n\t\t\t\tthrow new RuntimeException(\"Could not find lib directory in resources\");\n\t\t\t}\n\n\t\t\t// Create target directory if it doesn't exist\n\t\t\tPath targetDir = Path.of(workDir);\n\t\t\tif (!Files.exists(targetDir)) {\n\t\t\t\tFiles.createDirectories(targetDir);\n\t\t\t}\n\n\t\t\t// Get all JAR files from lib directory\n\t\t\tPath libPath = Path.of(libUrl.toURI());\n\t\t\ttry (var stream = Files.walk(libPath)) {\n\t\t\t\tstream.filter(path -> path.toString().endsWith(\".jar\")).forEach(jarPath -> {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tPath targetPath = targetDir.resolve(jarPath.getFileName());\n\t\t\t\t\t\tFiles.copy(jarPath, targetPath, java.nio.file.StandardCopyOption.REPLACE_EXISTING);\n\t\t\t\t\t}\n\t\t\t\t\tcatch (IOException e) {\n\t\t\t\t\t\tthrow new RuntimeException(\"Failed to copy JAR file: \" + jarPath, e);","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/utils/FileUtils.java#L61-L97","documentation":"FileUtils.copyResourceJarToWorkDir locates the 'lib' directory on the classpath (expected to contain JAR files bundled in resources) and copies its contents into the working directory. When classLoader.getResource(\"lib\") returns null — the resource is not packaged — this RuntimeException is thrown.","triggerScenarios":"Calling copyResourceJarToWorkDir when the classpath has no 'lib' resource: the lib directory was not included in the JAR, it sits in a module not on the runtime classpath, or it is referenced from a different ClassLoader (e.g. Spring Boot fat-jar nested URLs, custom classloader).","commonSituations":"Running in a Spring Boot executable jar where resources/lib was excluded by build config, missing maven resource include for the lib folder, running from an IDE with different resource roots, or shading/relocation that dropped the directory.","solutions":["Add the lib directory to src/main/resources and ensure Maven includes it (default resources filtering excludes nothing by default; check <resources> config).","Rebuild/repackage so lib/*.jar is present inside the artifact.","If running in Spring Boot, verify the resource is visible via getClass().getClassLoader().getResource(\"lib\") and consider extracting nested-jar resources with FileSystem handling.","If no bundled JARs are needed, skip the call instead of failing."],"exampleFix":"<!-- before: pom.xml excludes resources -->\n<resources><resource><directory>src/main/resources</directory><excludes><exclude>lib/**</exclude></excludes></resource></resources>\n<!-- after: include lib -->\n<resources><resource><directory>src/main/resources</directory></resource></resources>","handlingStrategy":"validation","validationCode":"URL libUrl = FileUtils.class.getClassLoader().getResource(\"lib\");\nif (libUrl == null) {\n    throw new IllegalStateException(\"lib directory missing from classpath — check packaging\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    FileUtils.copyResourceJarToWorkDir(workDir);\n} catch (RuntimeException e) {\n    if (e.getMessage().contains(\"Could not find lib directory\")) {\n        logger.error(\"resources/lib not packaged; verify build includes src/main/resources/lib\");\n    }\n    throw e;\n}","preventionTips":["Verify the packaged artifact contains lib/ (jar tf app.jar | grep lib).","Check Maven/Gradle resource includes/excludes after any build config change.","Test from both IDE and packaged-jar runs — classpath layouts differ.","Account for Spring Boot nested-jar resource URLs."],"tags":["classpath","resources","jar"],"backgroundTag":"resource-not-found","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}