spring-projects/spring-boot · error · MojoExecutionException
Unable to build classpath
Error message
Unable to build classpath
What it means
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.
Source
Thrown at build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java:388
}
args.addAll(classpath.args(true));
}
catch (Exception ex) {
throw new MojoExecutionException("Could not build classpath", ex);
}
}
protected URL[] getClassPathUrls() throws MojoExecutionException {
try {
List<URL> urls = new ArrayList<>();
addAdditionalClasspathLocations(urls);
addResources(urls);
addProjectClasses(urls);
addDependencies(urls);
return urls.toArray(new URL[0]);
}
catch (IOException ex) {
throw new MojoExecutionException("Unable to build classpath", ex);
}
}
private void addAdditionalClasspathLocations(List<URL> urls) throws MalformedURLException {
if (this.additionalClasspathElements != null) {
for (String element : this.additionalClasspathElements) {
urls.add(new File(element).toURI().toURL());
}
}
}
private void addResources(List<URL> urls) throws IOException {
if (this.addResources) {
for (Resource resource : this.project.getResources()) {
File directory = new File(resource.getDirectory());
urls.add(directory.toURI().toURL());
for (File classesDirectory : getClassesDirectories()) {
FileUtils.removeDuplicatesFromOutputDirectory(classesDirectory, directory);View on GitHub (pinned to 5b2dbdbb8b)
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.
Example fix
// before — system-scoped dependency with a bad systemPath
<dependency>
<groupId>com.example</groupId><artifactId>x</artifactId><version>1</version>
<scope>system</scope><systemPath>lib/x.jar</systemPath>
</dependency>
// after — absolute path that exists
<systemPath>${project.basedir}/lib/x.jar</systemPath> Defensive patterns
Strategy: validation
Validate before calling
// Ensure all runtime/test artifacts resolve before running
// mvn dependency:resolve -DincludeScope=runtime
// In Java (integration test):
import org.apache.maven.project.MavenProject;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
void assertAllArtifactsHaveFiles(MavenProject project) {
for (Artifact a : project.getArtifacts()) {
if (a.getFile() == null || !a.getFile().exists()) {
throw new IllegalStateException("Artifact without file: " + a);
}
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Could not build classpath
- Invalid URL for {}
- Failed to load layers configuration with name '%s': '%s' not
- Process terminated with exit code: {}
- Process execution failed
AI-assisted analysis of spring-projects/spring-boot@5b2dbdbb8b (2026-08-04).
Data as JSON: /data/errors/0273abfb2d486738.json.
Report an issue: GitHub.