{"record":{"id":"97967f93cecb3bfe","repo":"apache/maven","slug":"pom-file-specified-with-the-f-file-command-l","errorCode":null,"errorMessage":"POM file {} specified with the -f/--file command line argument does not exist","messagePattern":"POM file (.+?) specified with 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":376,"sourceCode":"        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.\n        RootLocator rootLocator =\n                ServiceLoader.load(RootLocator.class).iterator().next();\n        cliRequest.rootDirectory = rootLocator.findRoot(topDirectory);\n\n        //","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java#L358-L394","documentation":"During the early -f/--file scan in MavenCli, the value following -f/--file is resolved against the top directory; if it is neither an existing directory nor an existing regular file, 'POM file <arg> specified with the -f/--file command line argument does not exist' is printed to stderr and ExitException terminates the CLI with exit code 1 before any parsing or container startup happens.","triggerScenarios":"mvn -f path/to/pom.xml (or --file) where the path does not exist relative to the current working directory: typo, wrong working directory, module pom deleted or renamed, or a quoted path containing stray characters (the CLI strips leading/trailing quotes before resolving).","commonSituations":"Running mvn -f subdir/pom.xml from the wrong module root; CI checkouts where the expected module path moved; renamed pom.xml (e.g. to pom.xml.template) still referenced in scripts; Windows path quoting issues where quotes reach the JVM.","solutions":["Verify the file exists from the directory you launch mvn from: ls <value-of-f>","Correct the path or cd into the module and run mvn without -f","In scripts, derive the path robustly (absolute path via $(pwd)) rather than assuming the launch directory","Re-check the path after moving/renaming modules in a multi-module repo"],"exampleFix":"# before\nmvn -f mudules/app/pom.xml package   # typo\n\n# after\nmvn -f modules/app/pom.xml package","handlingStrategy":"validation","validationCode":"import java.nio.file.*;\n\n// validate a -f/--file value before launching Maven\nPath p = Paths.get(fValue);\nif (!(Files.isDirectory(p) || Files.isRegularFile(p))) {\n    throw new IllegalArgumentException(\n        \"-f target does not exist relative to \" + System.getProperty(\"user.dir\") + \": \" + fValue);\n}","typeGuard":null,"tryCatchPattern":"catch (ExitException e) {\n    if (stderrCapture.contains(\"specified with the -f/--file command line argument does not exist\")) {\n        // recompute the correct module path (e.g. locate pom.xml upward) and retry once\n        Path pom = findPomUpwards(Paths.get(\"\").toAbsolutePath());\n        if (pom != null) retryWithArguments(replaceArgument(args, fValue, pom.toString()));\n    }\n}","preventionTips":["In scripts, compute -f from a verified absolute base: mvn -f \"$(pwd)/modules/app/pom.xml\"","After moving or renaming modules, grep build scripts for stale -f paths","On Windows, check for stray literal quotes in path arguments — Maven strips only leading/trailing ones"],"tags":["maven","cli","pom","file-not-found","path"],"backgroundTag":"file-not-found","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}