{"record":{"id":"471fdb3a65af504f","repo":"apache/maven","slug":"directory-extracted-from-the-f-file-command","errorCode":null,"errorMessage":"Directory {} extracted from the -f/--file command-line argument {} does not exist","messagePattern":"Directory (.+?) extracted from the -f/--file command-line argument (.+?) does not exist","errorType":"console","errorClass":"ExitException","httpStatus":null,"severity":"error","filePath":"compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java","lineNumber":371,"sourceCode":"        }\n\n        // We need to locate the top level project which may be pointed at using\n        // the -f/--file option.  However, the command line isn't parsed yet, so\n        // we need to iterate through the args to find it and act upon it.\n        Path topDirectory = fileSystem.getPath(cliRequest.workingDirectory);\n        boolean isAltFile = false;\n        for (String arg : cliRequest.args) {\n            if (isAltFile) {\n                // this is the argument following -f/--file\n                Path path = topDirectory.resolve(stripLeadingAndTrailingQuotes(arg));\n                if (Files.isDirectory(path)) {\n                    topDirectory = path;\n                } else if (Files.isRegularFile(path)) {\n                    topDirectory = path.getParent();\n                    if (!Files.isDirectory(topDirectory)) {\n                        System.err.println(\"Directory \" + topDirectory\n                                + \" extracted from the -f/--file command-line argument \" + arg + \" does not exist\");\n                        throw new ExitException(1);\n                    }\n                } else {\n                    System.err.println(\n                            \"POM file \" + arg + \" specified with the -f/--file command line argument does not exist\");\n                    throw new ExitException(1);\n                }\n                break;\n            } else {\n                // Check if this is the -f/--file option\n                isAltFile = arg.equals(\"-f\") || arg.equals(\"--file\");\n            }\n        }\n        topDirectory = getCanonicalPath(topDirectory);\n        cliRequest.topDirectory = topDirectory;\n        // We're very early in the process, and we don't have the container set up yet,\n        // so we rely on the JDK services to eventually look up a custom RootLocator.\n        // This is used to compute {@code session.rootDirectory} but all {@code project.rootDirectory}\n        // properties will be computed through the RootLocator found in the container.","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java#L353-L389","documentation":"While pre-scanning raw arguments for -f/--file, MavenCli resolves the value against the current top directory. If the value is an existing regular file (a POM), its parent directory becomes the new top directory; when that parent then fails Files.isDirectory (concurrently removed, a dangling symlink used as the file's parent, or a permission-denied stat), 'Directory <parent> extracted from the -f/--file command-line argument <arg> does not exist' is printed and ExitException stops startup with code 1.","triggerScenarios":"mvn -f <pom> where <pom> resolves to a regular file but its parent directory is not a usable directory at check time — parent symlink chain broken, directory deleted between the two checks, or unusual filesystems (some network/FUSE mounts) where isDirectory on the parent fails.","commonSituations":"Pointing -f at a path through a symlinked directory whose target was moved; build scripts racing with directory cleanup; container mounts where the parent directory is present in the image but masked at runtime.","solutions":["Re-run with the parent directory itself: mvn -f /real/parent/dir (Maven will find pom.xml there)","Replace symlinked intermediate directories in the -f path with the real path (readlink -f to canonicalize)","Verify with ls -la that every path segment of the -f argument is a real directory","If a script deletes/recreates the module directory, ensure it completes before mvn starts"],"exampleFix":"# before: 'build' is a dangling symlink\nmvn -f ./build/pom.xml\n\n# after: use the real directory\nmvn -f /workspace/modules/app","handlingStrategy":"validation","validationCode":"import java.nio.file.*;\n\n// pre-check a -f argument before invoking Maven\nPath arg = Paths.get(fValue).toRealPath(); // throws if any symlink is broken\nPath topDir = Files.isDirectory(arg) ? arg : arg.getParent();\nif (!Files.isDirectory(topDir)) {\n    throw new IllegalArgumentException(\"-f argument parent is not a usable directory: \" + topDir);\n}","typeGuard":null,"tryCatchPattern":"catch (ExitException e) {\n    if (stderrCapture.contains(\"extracted from the -f/--file command-line argument\")) {\n        // pass the parent directory itself instead of the pom path and retry once\n        retryWithArguments(replaceArgument(args, fValue, topDirectoryAsString));\n    }\n}","preventionTips":["Canonicalize -f paths in wrapper scripts with readlink -f / realpath before invoking mvn","Avoid symlinks in module paths on shared build machines; use real checkout paths","Have scripts verify each path segment exists before launching the build"],"tags":["maven","cli","path","symlink","filesystem"],"backgroundTag":"path-not-found","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}