{"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":388,"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":370,"sourceCodeEnd":406,"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#L370-L406","documentation":"Thrown by AbstractRunMojo.getClassPathUrls as a MojoExecutionException wrapping an IOException raised while assembling the URL list for the run classpath — specifically from addResources, addProjectClasses, or addDependencies (addAdditionalClasspathLocations throws MalformedURLException which is an IOException). It differs from error 22 in that it fires during URL collection, before ClassPath.of is ever called.","triggerScenarios":"addResources=true (spring-boot.run.addResources) with a resource directory that cannot be converted to a URL; an artifact whose getFile() returns null or a path that fails File.toURI().toURL(); a dependency artifact with a file path containing characters that break URL conversion; addDependencies iterating over artifacts whose files are missing from the local repo.","commonSituations":"Running spring-boot:run after a partial mvn clean that deleted dependency jars from the local cache; a <resource><directory> pointing at a non-existent folder combined with addResources=true; corrupted local Maven repository entries; a system-scoped dependency whose systemPath is invalid.","solutions":["Run mvn dependency:resolve to confirm all runtime artifacts resolve and have files.","If using spring-boot.run.addResources=true, confirm every <resource><directory> exists.","Run mvn clean spring-boot:run to rule out stale target state.","Inspect the wrapped IOException cause to identify the exact artifact or resource that failed."],"exampleFix":"// before — system-scoped dependency with a bad systemPath\n<dependency>\n  <groupId>com.example</groupId><artifactId>x</artifactId><version>1</version>\n  <scope>system</scope><systemPath>lib/x.jar</systemPath>\n</dependency>\n// after — absolute path that exists\n<systemPath>${project.basedir}/lib/x.jar</systemPath>","handlingStrategy":"validation","validationCode":"// Ensure all runtime/test artifacts resolve before running\n// mvn dependency:resolve -DincludeScope=runtime\n// In Java (integration test):\nimport org.apache.maven.project.MavenProject;\nimport java.util.Set;\nimport org.apache.maven.artifact.Artifact;\n\nvoid assertAllArtifactsHaveFiles(MavenProject project) {\n    for (Artifact a : project.getArtifacts()) {\n        if (a.getFile() == null || !a.getFile().exists()) {\n            throw new IllegalStateException(\"Artifact without file: \" + a);\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run mvn dependency:resolve as a pre-step if you suspect repo corruption.","Avoid system-scoped dependencies with relative systemPath; use absolute paths or install:install-file.","Confirm every <resource><directory> exists when spring-boot.run.addResources=true."],"tags":["maven","spring-boot","run","classpath","dependencies"],"analyzedSha":"5b2dbdbb8be64415eb6552f81ff7c449c8d251e6","analyzedAt":"2026-08-04T18:53:14.967Z","schemaVersion":2}