独自の Archetypeの作成
参考
準備
以下のようなディレクトリ構成にする。
-- pom.xml |
親pom.xmlの作成
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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.yamkazu</groupId> <artifactId>archetype-simple-jar</artifactId> <packaging>maven-archetype</packaging> <version>1.0</version> <build> <extensions> <extension> <groupId>org.apache.maven.archetype</groupId> <artifactId>archetype-packaging</artifactId> <version>2.0-alpha-4</version> </extension> </extensions> <plugins> <plugin> <artifactId>maven-archetype-plugin</artifactId> <version>2.0-alpha-4</version> <extensions>true</extensions> </plugin> </plugins> </build> </project>
packagingにmaven-pluginを設定するところがポイント。
テンプレートファイルの作成
あとsrcの中にファイルを突っ込んでいくだけ。
archetype.xml
<archetype> <id>maven-archetype-sample</id> <sources> <source>src/main/java/Sample.java</source> </sources> <resources> <resource>src/main/resources/Sample.properties</resource> </resources> <testSources> </testSources> <siteResources> </siteResources> </archetype>
archetype.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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>${groupId}</groupId> <artifactId>${artifactId}</artifactId> <packaging>jar</packaging> <version>${version}</version> <build> <resources> <resource> <filtering>false</filtering> <directory>src/main/resources</directory> </resource> <resource> <filtering>false</filtering> <directory>src/main/java</directory> <includes> <include>**</include> </includes> <excludes> <exclude>**/*.java</exclude> </excludes> </resource> </resources> <testResources> <testResource> <filtering>false</filtering> <directory>src/test/resources</directory> </testResource> <testResource> <filtering>false</filtering> <directory>src/test/java</directory> <includes> <include>**</include> </includes> <excludes> <exclude>**/*.java</exclude> </excludes> </testResource> </testResources> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-eclipse-plugin</artifactId> <configuration> <downloadSources>true</downloadSources> <downloadJavadoc>true</downloadJavadoc> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.5</version> <scope>test</scope> </dependency> </dependencies> </project>
あとは省略
使い方
インストール
mvn install
使用する
mvn archetype:create -DarchetypeGroupId=org.yamkazu -DarchetypeArtifactId=simple-jar -DarchetypeVersion=1.0 -DgroupId=test -DartifactId=hogehoge