{"record":{"id":"6941887bf6e6e247","repo":"spring-projects/spring-boot","slug":"could-not-build-classpath","errorCode":null,"errorMessage":"Could not build classpath","messagePattern":"Could not build classpath","errorType":"exception","errorClass":"MojoExecutionException","httpStatus":null,"severity":"error","filePath":"build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java","lineNumber":393,"sourceCode":"\t\t\t\tif (i < this.profiles.length - 1) {\n\t\t\t\t\targ.append(\",\");\n\t\t\t\t}\n\t\t\t}\n\t\t\targuments.getArgs().addFirst(arg.toString());\n\t\t\tlogArguments(\"Active profile\", this.profiles);\n\t\t}\n\t}\n\n\tprivate void addClasspath(List<String> args) throws MojoExecutionException {\n\t\ttry {\n\t\t\tClassPath classpath = ClassPath.of(getClassPathUrls());\n\t\t\tif (getLog().isDebugEnabled()) {\n\t\t\t\tgetLog().debug(\"Classpath for forked process: \" + classpath);\n\t\t\t}\n\t\t\targs.addAll(classpath.args(true));\n\t\t}\n\t\tcatch (Exception ex) {\n\t\t\tthrow new MojoExecutionException(\"Could not build classpath\", ex);\n\t\t}\n\t}\n\n\tprotected URL[] getClassPathUrls() throws MojoExecutionException {\n\t\ttry {\n\t\t\tList<URL> urls = new ArrayList<>();\n\t\t\taddAdditionalClasspathLocations(urls);\n\t\t\taddResources(urls);\n\t\t\taddProjectClasses(urls);\n\t\t\taddDependencies(urls);\n\t\t\treturn urls.toArray(new URL[0]);\n\t\t}\n\t\tcatch (IOException ex) {\n\t\t\tthrow new MojoExecutionException(\"Unable to build classpath\", ex);\n\t\t}\n\t}\n\n\tprivate void addAdditionalClasspathLocations(List<URL> urls) throws MalformedURLException {","sourceCodeStart":375,"sourceCodeEnd":411,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/270dfe353fb830fd69b823a8a859287ff103854b/build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java#L375-L411","documentation":"MojoExecutionException thrown by AbstractRunMojo.addClasspath when ANY exception escapes ClassPath.of(getClassPathUrls()) or the subsequent args(true) call. The method deliberately catches a broad Exception because the classpath assembly for the forked process can fail in many ways (URL construction, dependency resolution, resource scanning). The original exception is chained as the cause.","triggerScenarios":"Running `spring-boot:run` (or any forked run) where getClassPathUrls() throws (MalformedURLException from addAdditionalClasspathLocations/addResources/addDependencies), or ClassPath.of rejects the URL array, or args(true) fails.","commonSituations":"Badly formed <additionalClasspathElements> entry (not a valid path/URL); a dependency JAR is missing from the local repo; resources directory points to a non-existent location; version mismatch leaving a dependency unresolved; running on a JDK that rejects a constructed URL.","solutions":["Inspect the chained cause (ex) — it identifies which sub-step (additional classpath, resources, classes, or dependencies) failed.","Run with -X (debug) to see the logged 'Classpath for forked process' attempt and the failing URL.","Validate every <additionalClasspathElements> value as a real filesystem path.","Run `mvn dependency:tree` to confirm all compile/runtime dependencies resolve, then re-run spring-boot:run."],"exampleFix":"// before: <additionalClasspathElements><additionalClasspathElement>/opt/lib:bad|path</additionalClasspathElement></additionalClasspathElements>\n// after:  <additionalClasspathElements><additionalClasspathElement>/opt/lib/good-path.jar</additionalClasspathElement></additionalClasspathElements>","handlingStrategy":"validation","validationCode":"// Sanity-check additionalClasspathElements before running spring-boot:run:\nfor (String e : additionalClasspathElements) {\n    if (e == null || e.isEmpty() || !new File(e).exists()) {\n        throw new IllegalArgumentException(\"Bad additionalClasspathElement: \" + e);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    // invoke run/forked goal\n} catch (MojoExecutionException ex) {\n    if (\"Could not build classpath\".equals(ex.getMessage())) {\n        Throwable c = ex.getCause(); // the actual URL/path failure\n    }\n    throw ex;\n}","preventionTips":["Always run `mvn compile` before `spring-boot:run` so class folders exist.","Validate every <additionalClasspathElements> path with a CI assertion.","Run `mvn dependency:tree` to confirm all runtime deps resolve."],"tags":["spring-boot","maven-plugin","classpath","run","dependencies"],"backgroundTag":null,"analyzedSha":"270dfe353fb830fd69b823a8a859287ff103854b","analyzedAt":"2026-08-11T19:42:06.541Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}