{"record":{"id":"0273abfb2d486738","repo":"spring-projects/spring-boot","slug":"unable-to-build-classpath","errorCode":null,"errorMessage":"Unable to build classpath","messagePattern":"Unable to 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":407,"sourceCode":"\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 {\n\t\tif (this.additionalClasspathElements != null) {\n\t\t\tfor (String element : this.additionalClasspathElements) {\n\t\t\t\turls.add(new File(element).toURI().toURL());\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate void addResources(List<URL> urls) throws IOException {\n\t\tif (this.addResources) {\n\t\t\tfor (Resource resource : this.project.getResources()) {\n\t\t\t\tFile directory = new File(resource.getDirectory());\n\t\t\t\turls.add(directory.toURI().toURL());\n\t\t\t\tfor (File classesDirectory : getClassesDirectories()) {\n\t\t\t\t\tFileUtils.removeDuplicatesFromOutputDirectory(classesDirectory, directory);","sourceCodeStart":389,"sourceCodeEnd":425,"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#L389-L425","documentation":"MojoExecutionException thrown by AbstractRunMojo.getClassPathUrls when an IOException occurs while building the URL list for the forked run classpath. Unlike the broader sibling in addClasspath, this catch is scoped to IOException only and originates inside getClassPathUrls itself — emitted by addResources/addProjectClasses/addDependencies or URL array conversion.","triggerScenarios":"An IOException raised by addResources, addProjectClasses, addDependencies, or the URL construction during spring-boot:run classpath assembly. E.g., a File.toURI().toURL() chain throws, or a filesystem walk over resources fails.","commonSituations":"Output directories (target/classes, target/test-classes) missing or unreadable; a dependency artifact file path is stale; IDE reimport left the local repo inconsistent; running run goal before compile/test-compile phase so required class folders don't exist yet.","solutions":["Run `mvn clean compile` first so target/classes and target/test-classes exist before spring-boot:run.","Inspect the chained IOException for the offending path.","Run `mvn dependency:resolve` to ensure every runtime artifact file is present on disk.","Remove any stale <additionalClasspathElements> pointing at deleted directories."],"exampleFix":"// before: mvn spring-boot:run   (before compile, target/classes absent)\n// after:  mvn clean compile spring-boot:run","handlingStrategy":"try-catch","validationCode":"// Pre-flight: ensure the standard class folders exist before run:\nList<String> required = List.of(\"target/classes\", \"target/test-classes\");\nfor (String p : required) {\n    if (!new File(p).isDirectory()) {\n        // run `mvn compile` first\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    // invoke run goal\n} catch (MojoExecutionException ex) {\n    if (\"Unable to build classpath\".equals(ex.getMessage()) && ex.getCause() instanceof IOException) {\n        // most likely missing output folder — run `mvn clean compile` and retry\n    }\n    throw ex;\n}","preventionTips":["Bind spring-boot:run after compile in the lifecycle or always run `mvn compile spring-boot:run`.","Don't delete target/ between phases.","Pin dependency versions to avoid resolution drift."],"tags":["spring-boot","maven-plugin","classpath","io","run"],"backgroundTag":null,"analyzedSha":"270dfe353fb830fd69b823a8a859287ff103854b","analyzedAt":"2026-08-11T19:42:06.541Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}