新建一个 archetype 项目:
mvn archetype:create -DgroupId=com.yunling.conf -DartifactId=prof-archetype -DarchetypeArtifactId=maven-archetype-archetype
模版文件:src/main/resources/archetype-resources/pom.xml
我修改后的内容如下:
pom<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>$com.yunling.prof</groupId>
<artifactId>$prof-archetype</artifactId>
<packaging>war</packaging>
<version>$1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/java</source>
<source>src/resources</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifaceId>maven-war-plugin</artifactId>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
<outputDirectory>WebContent/WEB-INF/classes</outputDiretory>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
安装项目:
cd prof-archetype
mvn install
这样就可以使用它创建新项目:
mvn archetype:create -DgroupId=cn.lingyun.app -DartifactId=webdemo -DarchetypeArtifactId=prof-archetype -DarchetypeVersion=1.0-SNAPSHOT