Maven自定义原型无法在包路径下生成空conf目录问题排查
conf Directory Not Generating Hey there, let's break down why your empty conf directory isn't being created when generating a project from your archetype, and how to fix it.
The Root Cause
Maven Archetype works by scanning and copying files defined in your archetype-metadata.xml—it doesn't automatically include empty directories because there are no files to match against your file set rules. That's why adding a dummy file (like delme.txt) and updating the include rule made the directory appear: the file gave Archetype something to copy, which in turn created the parent directory.
The Simple Fix: Use a Placeholder File
The easiest way to preserve empty directories in your archetype is to add a lightweight placeholder file to the conf directory, then update your archetype-metadata.xml to include it. A common choice is .gitkeep (Git uses this to track empty directories, but it works perfectly here even if you don't use Git).
Here's what to do:
- In your archetype's
archetype-resources/src/main/java/confdirectory, create a file named.gitkeep(it can be completely empty). - Update your
archetype-metadata.xmlto include this placeholder in the existingsrc/main/javafile set:<fileSet filtered="false" packaged="true" encoding="UTF-8"> <directory>src/main/java</directory> <includes> <include>**/*.java</include> <include>**/conf/.gitkeep</include> </includes> </fileSet>
When you generate a project now, the conf directory will be created along with the .gitkeep file. Users can delete the .gitkeep later if they want, but the empty directory will stay intact.
Bonus: About the "No Archetype IT projects" Warning
That warning you saw during mvn install is unrelated to your directory issue—it just means Maven couldn't find the optional integration test directory for the archetype. If you want to get rid of it, create a src/test/resources/projects directory (you can leave it empty), or just ignore it if you don't need archetype integration tests.
内容的提问来源于stack exchange,提问作者Oxnard

