maven自定义archetype
maven打包命令:
mvn clean install -Dmaven.test.skip=true
创建一个maven项目, 目录结构如下:
上面需要重点的文件:
1、src/main/resources/archetype-resources/pom.xml
文件内容大致如下:
<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/xsd/maven-4.0.0.xsd"> <groupId>${groupId}></groupId> <artifactId>${artifactId}</artifactId> <version>${version}</version> <packaging>war</packaging> <!-- 这里必须配置,不然生成的项目的配置文件会有编码问题 --> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <!-- Servlet配置 --> <!-- 1.Servlet --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> </dependency> <!-- 2.Jsp --> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> </dependency> <!-- Spring and Transactions --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> </dependency> <!-- 测试工具 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> </dependencies> <profiles> <!-- 开发环境 --> <profile> <id>dev</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <profiles.active>dev</profiles.active> </properties> <build> <filters> <filter>${basedir}/src/main/filters/dev.properties</filter> </filters> </build> </profile> </profiles> <build> <finalName>${artifactId}</finalName> <resources> <resource> <directory>${basedir}/src/main/resources</directory> <filtering>true</filtering> </resource> </resources> <pluginManagement> <plugins> <!-- 配置checkstyle插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <configuration> <configLocation>${basedir}/src/main/config/code_checker/micaicms_checkstyle_v1.0.xml</configLocation> </configuration> </plugin> <!-- 配置findbugs插件 --> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>findbugs-maven-plugin</artifactId> <configuration> <configLocation>${basedir}/src/main/config/code_checker/micaicms_findbugs_v1.0.xml</configLocation> </configuration> </plugin> </plugins> </pluginManagement> </build> </project>
上面的pom是配置要生成的项目的pom。
2、src/main/resources/archetype-resources/**/**
此目录下面的文件是要生成的项目的文件
3、src\main\resources\META-INF\maven\archetype-metadata.xml
此文件是配置文件,内容如下:
<?xml version="1.0" encoding="UTF-8"?> <archetype-descriptor name="neris-web-archetype"> <fileSets> <fileSet filtered="true" encoding="UTF-8" packaged="true"> <directory>src/main/java</directory> <includes> <include>**/*.**</include> </includes> </fileSet> <fileSet filtered="true" encoding="UTF-8"> <directory>src/main/resources</directory> <includes> <include>**/*.**</include> </includes> </fileSet> <fileSet filtered="true" encoding="UTF-8"> <directory>src/main/webapp</directory> <includes> <include>**/*.**</include> </includes> </fileSet> <fileSet filtered="true" encoding="UTF-8"> <directory>src/main/config</directory> <includes> <include>**/*.**</include> </includes> </fileSet> <fileSet filtered="true" encoding="UTF-8"> <directory>src/main/filters</directory> <includes> <include>**/*.**</include> </includes> </fileSet> <fileSet filtered="true" encoding="UTF-8" packaged="true"> <directory>src/test/java</directory> <includes> <include>**/*.**</include> </includes> </fileSet> <fileSet filtered="true" encoding="UTF-8"> <directory>src/test/resources</directory> <includes> <include>**/*.**</include> </includes> </fileSet> </fileSets> </archetype-descriptor>
然后install这个项目。
执行命令更新你的本地仓库的索引
mvn archetype:update-local-catalog
创建项目
mvn archetype:generate -DarchetypeCatalog=local