通过maven命令创建的项目总是和别人不一样,少了一些目录。比如:

【maven】archetype创建项目 目录丢失_maven

通过这个quick-start生成的目录结构没有resources文件夹:

【maven】archetype创建项目 目录丢失_maven_02

后来知道可以手动添加解决,但是貌似没人探究为什么会这样,忍不住略微查了查。

原来每一个archetype的模板也是一个jar文件,里面定义了项目的目录结构,可以从

​https://mvnrepository.com/artifact/org.apache.maven.archetypes/maven-archetype-quickstart/1.3​

下载到quick-start的jar文件,解压缩以后,在META-INF/maven目录下,有一个archetype.xml文件,这个文件就是定义结构的文件:

<archetype xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0 http://maven.apache.org/xsd/archetype-1.0.0.xsd">
<id>quickstart</id>

<sources>
<source>src/main/java/App.java</source>
</sources>
<testSources>
<source>src/test/java/AppTest.java</source>
</testSources>
</archetype>

这里并没有定义resouces文件夹。我们可以修改这个archetype,然后install到本地库。

使用webapp的模板也是一样的道理。

最后在官网有完整的介绍:

​https://maven.apache.org/guides/mini/guide-creating-archetypes.html​

【maven】archetype创建项目 目录丢失_apache_03