{"record":{"id":"055624f41a3f0c49","repo":"GoogleContainerTools/jib","slug":"nosuchfileexception-directory","errorCode":null,"errorMessage":"NoSuchFileException: <directory>","messagePattern":"NoSuchFileException: <directory>","errorType":"validation","errorClass":"NoSuchFileException","httpStatus":null,"severity":"error","filePath":"jib-core/src/main/java/com/google/cloud/tools/jib/api/JavaContainerBuilder.java","lineNumber":680,"sourceCode":"      }\n      String classpathString = String.join(\":\", classpathElements);\n      List<String> entrypoint = new ArrayList<>(4 + jvmFlags.size());\n      entrypoint.add(\"java\");\n      entrypoint.addAll(jvmFlags);\n      entrypoint.add(\"-cp\");\n      entrypoint.add(classpathString);\n      entrypoint.add(mainClass);\n      jibContainerBuilder.setEntrypoint(entrypoint);\n    }\n\n    return jibContainerBuilder;\n  }\n\n  private JavaContainerBuilder addDirectory(\n      List<PathPredicatePair> addedPaths, Path directory, Predicate<Path> filter)\n      throws NoSuchFileException, NotDirectoryException {\n    if (!Files.exists(directory)) {\n      throw new NoSuchFileException(directory.toString());\n    }\n    if (!Files.isDirectory(directory)) {\n      throw new NotDirectoryException(directory.toString());\n    }\n    addedPaths.add(new PathPredicatePair(directory, filter));\n    return this;\n  }\n\n  private void addFileToLayer(\n      Map<LayerType, FileEntriesLayer.Builder> layerBuilders,\n      LayerType layerType,\n      Path sourceFile,\n      AbsoluteUnixPath pathInContainer) {\n    if (!layerBuilders.containsKey(layerType)) {\n      layerBuilders.put(layerType, FileEntriesLayer.builder());\n    }\n    Instant modificationTime = modificationTimeProvider.get(sourceFile, pathInContainer);\n    layerBuilders.get(layerType).addEntry(sourceFile, pathInContainer, modificationTime);","sourceCodeStart":662,"sourceCodeEnd":698,"githubUrl":"https://github.com/GoogleContainerTools/jib/blob/fb949e2676afbbd7dd7a1ef61e20251931325654/jib-core/src/main/java/com/google/cloud/tools/jib/api/JavaContainerBuilder.java#L662-L698","documentation":"JavaContainerBuilder.addDirectory requires the directory passed to exist on the local filesystem. Before adding the directory to the build, it calls Files.exists(); if the path does not exist it throws NoSuchFileException with the directory path. This is a fail-fast check so users get a clear error about a missing resources/classes/dependencies directory rather than a silently incomplete image.","triggerScenarios":"Calling addResources(Path), addClasses(Path), addDependencies(Path) (or addDirectory directly) with a Path that does not exist on disk, e.g. a typo'd path or a directory created only by a later build phase.","commonSituations":"Pointing addResources at src/main/resources when the module was never built or the folder was cleaned; using a wrong project root in multi-module builds; running jib before the classes output directory (target/classes, build/classes) exists because no compilation ran; path spelled with wrong case or separator.","solutions":["Verify the directory exists at the path you pass before calling jib: Files.isDirectory(path) or ls the path.","Create the directory if your build legitimately produces it later: Files.createDirectories(resourcesDir) before calling addResources.","Fix the path - use correct project root, e.g. Paths.get(\"src/main/resources\") relative to the module, and check for typos/case.","Ensure your compile step runs before jib builds, so target/classes or build/classes exists.","If you intend to add a single file instead, use addFileToLayer-style APIs rather than a directory path."],"exampleFix":"// before\nJavaContainerBuilder.builder().addResources(Paths.get(\"src/main/resourcs\"));\n// after\nPath res = Paths.get(\"src/main/resources\");\nif (!Files.isDirectory(res)) { throw new IllegalStateException(\"missing resources dir: \" + res); }\nJavaContainerBuilder.builder().addResources(res);","handlingStrategy":"validation","validationCode":"if (!Files.isDirectory(dir)) throw new IllegalArgumentException(\"Missing directory: \" + dir);","typeGuard":"boolean isUsableDir(Path p) { return p != null && Files.isDirectory(p); }","tryCatchPattern":"try { builder.addResources(dir); } catch (NoSuchFileException e) { log.error(\"Directory not found: {}\", e.getFile()); throw new BuildSetupException(e); }","preventionTips":["Assert directory existence in an init step before configuring jib","Run compilation before jib so output directories exist","Use build-tool-provided paths (sourceSets.main.output) instead of hardcoded strings","Add Files.createDirectories for directories your build owns"],"tags":["filesystem","path","container-build"],"backgroundTag":"file-not-found","analyzedSha":"fb949e2676afbbd7dd7a1ef61e20251931325654","analyzedAt":"2026-09-06T14:04:09.491Z","contentChangedAt":"2026-09-06T14:04:09.491Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}