{"record":{"id":"c4630792c581be80","repo":"spring-projects/spring-boot","slug":"a-jar-or-war-file-is-required-for-building-image","errorCode":null,"errorMessage":"A jar or war file is required for building image","messagePattern":"A jar or war file is required for building image","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildImageMojo.java","lineNumber":325,"sourceCode":"\t\t\timage.setImagePlatform(this.imagePlatform);\n\t\t}\n\t\treturn customize(image.getBuildRequest(this.project.getArtifact(), content));\n\t}\n\n\tprivate TarArchive getApplicationContent(Owner owner, Libraries libraries, ImagePackager imagePackager) {\n\t\tImagePackager packager = getConfiguredPackager(() -> imagePackager);\n\t\treturn new PackagedTarArchive(owner, libraries, packager);\n\t}\n\n\tprivate File getArchiveFile() {\n\t\t// We can't use 'project.getArtifact().getFile()' because package can be done in a\n\t\t// forked lifecycle and will be null\n\t\tFile archiveFile = getTargetFile(this.finalName, this.classifier, this.sourceDirectory);\n\t\tif (!archiveFile.exists()) {\n\t\t\tarchiveFile = getSourceArtifact(this.classifier).getFile();\n\t\t}\n\t\tif (!archiveFile.exists()) {\n\t\t\tthrow new IllegalStateException(\"A jar or war file is required for building image\");\n\t\t}\n\t\treturn archiveFile;\n\t}\n\n\t/**\n\t * Return the {@link File} to use to back up the original source.\n\t * @return the file to use to back up the original source\n\t */\n\tprivate @Nullable File getBackupFile() {\n\t\t// We can't use 'project.getAttachedArtifacts()' because package can be done in a\n\t\t// forked lifecycle and will be null\n\t\tif (this.classifier != null) {\n\t\t\tFile backupFile = getTargetFile(this.finalName, null, this.sourceDirectory);\n\t\t\tif (backupFile.exists()) {\n\t\t\t\treturn backupFile;\n\t\t\t}\n\t\t\tArtifact source = getSourceArtifact(null);\n\t\t\tif (!this.classifier.equals(source.getClassifier())) {","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/270dfe353fb830fd69b823a8a859287ff103854b/build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildImageMojo.java#L307-L343","documentation":"IllegalStateException thrown by BuildImageMojo.getArchiveFile when no packaged archive can be located. The plugin first looks for target/<finalName>[<classifier>].<ext> in sourceDirectory, then falls back to the resolved source artifact's file. If neither exists, building a container image is impossible because the image tar needs an actual jar/war to embed.","triggerScenarios":"Invoking spring-boot:build-image before the package phase produced an archive; classifier mismatch so getTargetFile returns a non-existent file and getSourceArtifact(classifier).getFile() is also null; package ran in a forked lifecycle leaving no file at the expected path.","commonSituations":"Calling build-image directly without `mvn package spring-boot:build-image`; using a <classifier> that doesn't correspond to any produced artifact; repackaging skipped; outputDirectory/finalName customized so the plugin looks in the wrong place; CI step ordering omits package.","solutions":["Bind or run the goal as part of the package phase: `mvn package spring-boot:build-image`.","Confirm the configured <classifier> (if any) matches an artifact actually produced by the build.","Verify <finalName> and <sourceDirectory> so getTargetFile resolves to the real archive.","Ensure the package goal (jar/war packaging) is not skipped and runs in the same lifecycle."],"exampleFix":"// before: mvn spring-boot:build-image\n// after:  mvn clean package spring-boot:build-image","handlingStrategy":"validation","validationCode":"// Pre-build check: an archive must exist before build-image:\nString ext = \"jar\".equals(project.getPackaging()) ? \"jar\" : \"war\";\nFile archive = new File(sourceDirectory, finalName + (classifier == null ? \"\" : \"-\" + classifier) + \".\" + ext);\nif (!archive.exists()) {\n    throw new IllegalStateException(\"Run `mvn package` before build-image; missing \" + archive);\n}","typeGuard":null,"tryCatchPattern":"try {\n    // invoke build-image\n} catch (IllegalStateException ex) {\n    if (\"A jar or war file is required for building image\".equals(ex.getMessage())) {\n        // run package first, then retry\n    }\n    throw ex;\n}","preventionTips":["Always invoke build-image as `mvn package spring-boot:build-image`.","Bind build-image to the package phase in <executions>.","Double-check <classifier> and <finalName> against the produced artifact."],"tags":["spring-boot","maven-plugin","build-image","packaging","lifecycle"],"backgroundTag":null,"analyzedSha":"270dfe353fb830fd69b823a8a859287ff103854b","analyzedAt":"2026-08-11T19:42:06.541Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}