{"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":374,"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":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/5b2dbdbb8be64415eb6552f81ff7c449c8d251e6/build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java#L356-L392","documentation":"Thrown by AbstractRunMojo.addClasspath as a MojoExecutionException wrapping any Exception raised while turning the URL array (classes, resources, dependencies) into the -cp argument for the forked JVM. The URLs themselves are gathered first by getClassPathUrls(); this catch specifically guards the ClassPath.of(...).args(true) conversion step, so the cause typically indicates a malformed URL or a ClassPath formatting failure rather than a dependency-resolution problem.","triggerScenarios":"Running spring-boot:run with classpath URLs that contain characters ClassPath cannot encode; an additional classpath element (-Dspring-boot.run.additional-classpath-elements) pointing at a path whose File.toURI().toURL() fails; a corrupt artifact file path on disk that yields an invalid URL when the run mojo assembles the classpath.","commonSituations":"Passing -Dspring-boot.run.additional-classpath-elements with a relative or non-existent path; running on Windows where path-to-URL conversion is fragile; an artifact whose getFile() returns a path with spaces or special characters; stale target/classes after a partial clean.","solutions":["Run with -X (debug) to see the 'Classpath for forked process:' line and identify the offending element.","Verify every entry in spring-boot.run.additional-classpath-elements exists and is a directory or jar.","Run mvn clean to remove stale target/ contents that may produce malformed URLs.","Inspect the wrapped cause (MalformedURLException, URISyntaxException, etc.) to pinpoint the bad path."],"exampleFix":"// before\nmvn spring-boot:run -Dspring-boot.run.additional-classpath-elements=lib/extra\n// after — absolute, existing path\nmvn spring-boot:run -Dspring-boot.run.additional-classpath-elements=/abs/path/extra.jar","handlingStrategy":"validation","validationCode":"// Validate additional classpath elements before running\nimport java.io.File;\nimport java.util.List;\n\nvoid checkElements(List<String> elements) {\n    for (String e : elements) {\n        File f = new File(e);\n        if (!f.exists()) throw new IllegalArgumentException(\"Missing classpath element: \" + e);\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass absolute paths in spring-boot.run.additional-classpath-elements.","Run mvn clean before spring-boot:run when the build state is questionable.","Use -X to capture the exact classpath the plugin assembled when diagnosing."],"tags":["maven","spring-boot","run","classpath","configuration"],"analyzedSha":"5b2dbdbb8be64415eb6552f81ff7c449c8d251e6","analyzedAt":"2026-08-04T18:53:14.967Z","schemaVersion":2}