Spring Boot WS Maven构建报错:未找到XSD Schema文件
Hey there, I've run into this exact issue before when setting up JAXB with Spring Boot Web Services. Let's walk through the most common fixes to get your XSD-to-Java generation working smoothly:
1. Verify Your XSD File Path Configuration
The jaxb2-maven-plugin 1.6 defaults to looking for schemas in src/main/resources/schema. If your XSD files are stored elsewhere, you need to explicitly tell the plugin where to find them.
Add the schemaDirectory element to your plugin configuration to point to the correct folder. For example, if your XSDs are in src/main/xsd:
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>jaxb2-maven-plugin</artifactId> <version>1.6</version> <executions> <execution> <goals> <goal>xjc</goal> </goals> </execution> </executions> <configuration> <!-- Point to your actual XSD directory --> <schemaDirectory>src/main/xsd</schemaDirectory> <!-- Optional: Specify exact files if you don't want to scan the whole folder --> <!-- <schemaFiles>your-service-contract.xsd</schemaFiles> --> </configuration> </plugin>
2. Ensure Your XSD Files Are Included in the Scan
By default, the plugin uses a pattern of **/*.xsd to find schemas, but nested directories or non-standard filenames can sometimes slip through the cracks. Explicitly define includes to guarantee all your XSDs are picked up:
<configuration> <includes> <include>**/*.xsd</include> <!-- Add more patterns if your XSDs live in specific subfolders --> <!-- <include>wsdl-schemas/**/*.xsd</include> --> </includes> </configuration>
3. Double-Check Plugin Execution Setup
Make sure your plugin is bound to the correct Maven phase and the xjc goal is properly configured. Typos in the goal name or missing execution blocks are common culprits. Confirm your configuration has:
<executions> <execution> <phase>generate-sources</phase> <goals> <goal>xjc</goal> </goals> </execution> </executions>
4. Clean and Rebuild Your Project
Maven's cached build artifacts can sometimes cause odd, hard-to-debug issues. Run these commands to clear the cache and trigger a fresh schema generation:
mvn clean mvn generate-sources
If none of these work, double-check that your XSD files are actually present in the directory you specified (no typos in folder names or filenames!) and that they're valid XML schemas—invalid XSDs might also cause the plugin to fail silently in some cases.
内容的提问来源于stack exchange,提问作者iizAck

