Maven2/プラグインを自作する
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
// 下階層用テンプレート
#topicpath
----
//ここにコンテンツを記述します。
#contents
**プラグイン用Eclipseプロジェクトを作る [#z8b8ef14]
mvn archetype:create -DgroupId=nu.mine.kino.plugins \
-DartifactId=maven-hoge-plugin \
-DarchetypeArtifactId=maven-archety...
cd maven-hoge-plugin/
mvn eclipse:eclilpse
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>nu.mine.kino.plugins</groupId>
<artifactId>maven-hoge-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.0-SNAPSHOT</version>
<name>maven-hoge-plugin Maven Mojo</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
**プラグインのソースを書く。 [#d446f76c]
package nu.mine.kino.plugins;
/**
* Goal which touches a timestamp file.
*
* @goal touch <-Annotation
*
* @phase process-sources
*/
public class MyMojo extends AbstractMojo {
/**
* @parameter expression="${project.build.directory}"
* @required
*/
private File outputDirectory;
public void execute() throws MojoExecutionException {
File f = outputDirectory;
if (!f.exists()) {
f.mkdirs();
}
File touch = new File(f, "touch.txt");
FileWriter w = null;
try {
w = new FileWriter(touch);
w.write("touch.txt");
} catch (IOException e) {
throw new MojoExecutionException("Error creating f...
} finally {
if (w != null) {
try {
w.close();
} catch (IOException e) {
// ignore
}
}
}
}
}
**Mavenコマンドでローカルリポジトリにプラグインをインスト...
maven clean install
これで先のソースがローカルリポジトリにインストールされま...
**Mavenプロジェクトからインストールしたプラグインを呼び出...
さて、ローカルリポジトリにプラグインがインストールされた...
pom.xmlには以下のように追加します。
<build>
......
<plugin>
<groupId>nu.mine.kino.plugins</groupId>
<artifactId>maven-hoge-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
</plugin>
</plugins>
</build>
以下のコマンドで先のモジュールを呼び出します。
mvn nu.mine.kino.plugins:maven-hoge-plugin:1.0-SNAPSHOT:...
引数の意味。
mvn [groupId]:[artifactId]:[version]:[ゴール名]
なんだろ、ローカルにインストールされているだけなので、グ...
**アノテーション [#oaaf2b02]
**アノテーションやpomから生成されるファイル [#w283cabb]
上のアノテーションの記述やpom.xmlの情報から、プラグインフ...
maven-hoge-plugin-1.0-SNAPSHOT.jar#META-INF/maven/plugin...
に格納されています。内容は以下の通り。
<plugin>
<description></description>
<groupId>nu.mine.kino.plugins</groupId>
<artifactId>maven-hoge-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<goalPrefix>hoge</goalPrefix>
<isolatedRealm>false</isolatedRealm>
<inheritedByDefault>true</inheritedByDefault>
<mojos>
<mojo>
<goal>touch</goal>
<description>Goal which touches a timestamp file.<...
<requiresDirectInvocation>false</requiresDirectInv...
<requiresProject>true</requiresProject>
<requiresReports>false</requiresReports>
<aggregator>false</aggregator>
<requiresOnline>false</requiresOnline>
<inheritedByDefault>true</inheritedByDefault>
<phase>process-sources</phase>
<implementation>nu.mine.kino.plugins.MyMojo</imple...
<language>java</language>
<instantiationStrategy>per-lookup</instantiationSt...
<executionStrategy>once-per-session</executionStra...
<parameters>
<parameter>
<name>outputDirectory</name>
<type>java.io.File</type>
<required>true</required>
<editable>true</editable>
<description>Location of the file.</description>
</parameter>
</parameters>
<configuration>
<outputDirectory implementation="java.io.File">$...
</configuration>
</mojo>
</mojos>
<dependencies/>
</plugin>
-[[Mojoって何?>http://blog.goo.ne.jp/ikkoan/e/faee35340ce...
**所感 [#yf38b602]
、、、、、、これ、デバッグどうやるんだ??
**組み込みプロパティの一覧 [#r1207831]
-[[ParameterExpression>http://wiki.fdiary.net/maven2/?Par...
に一覧があります。感謝!
**関連リンク [#t80863c1]
-[[Your First Plugin>http://maven.apache.org/guides/plugi...
-[[Maven2のTipsを集めるWiki>http://wiki.fdiary.net/maven2...
-[[[Maven] Maven2 Plugin の作り方 >http://www.in-vitro.jp...
----
この記事は
#vote(おもしろかった[7],そうでもない[1])
- リポジトリ内の maven-metadata-local.xml に<prefix>hoge<...
- http://maven.apache.org/guides/plugin/guide-java-plugin...
#comment
#topicpath
SIZE(10){現在のアクセス:&counter;}
終了行:
// 下階層用テンプレート
#topicpath
----
//ここにコンテンツを記述します。
#contents
**プラグイン用Eclipseプロジェクトを作る [#z8b8ef14]
mvn archetype:create -DgroupId=nu.mine.kino.plugins \
-DartifactId=maven-hoge-plugin \
-DarchetypeArtifactId=maven-archety...
cd maven-hoge-plugin/
mvn eclipse:eclilpse
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>nu.mine.kino.plugins</groupId>
<artifactId>maven-hoge-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>1.0-SNAPSHOT</version>
<name>maven-hoge-plugin Maven Mojo</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
**プラグインのソースを書く。 [#d446f76c]
package nu.mine.kino.plugins;
/**
* Goal which touches a timestamp file.
*
* @goal touch <-Annotation
*
* @phase process-sources
*/
public class MyMojo extends AbstractMojo {
/**
* @parameter expression="${project.build.directory}"
* @required
*/
private File outputDirectory;
public void execute() throws MojoExecutionException {
File f = outputDirectory;
if (!f.exists()) {
f.mkdirs();
}
File touch = new File(f, "touch.txt");
FileWriter w = null;
try {
w = new FileWriter(touch);
w.write("touch.txt");
} catch (IOException e) {
throw new MojoExecutionException("Error creating f...
} finally {
if (w != null) {
try {
w.close();
} catch (IOException e) {
// ignore
}
}
}
}
}
**Mavenコマンドでローカルリポジトリにプラグインをインスト...
maven clean install
これで先のソースがローカルリポジトリにインストールされま...
**Mavenプロジェクトからインストールしたプラグインを呼び出...
さて、ローカルリポジトリにプラグインがインストールされた...
pom.xmlには以下のように追加します。
<build>
......
<plugin>
<groupId>nu.mine.kino.plugins</groupId>
<artifactId>maven-hoge-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
</plugin>
</plugins>
</build>
以下のコマンドで先のモジュールを呼び出します。
mvn nu.mine.kino.plugins:maven-hoge-plugin:1.0-SNAPSHOT:...
引数の意味。
mvn [groupId]:[artifactId]:[version]:[ゴール名]
なんだろ、ローカルにインストールされているだけなので、グ...
**アノテーション [#oaaf2b02]
**アノテーションやpomから生成されるファイル [#w283cabb]
上のアノテーションの記述やpom.xmlの情報から、プラグインフ...
maven-hoge-plugin-1.0-SNAPSHOT.jar#META-INF/maven/plugin...
に格納されています。内容は以下の通り。
<plugin>
<description></description>
<groupId>nu.mine.kino.plugins</groupId>
<artifactId>maven-hoge-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<goalPrefix>hoge</goalPrefix>
<isolatedRealm>false</isolatedRealm>
<inheritedByDefault>true</inheritedByDefault>
<mojos>
<mojo>
<goal>touch</goal>
<description>Goal which touches a timestamp file.<...
<requiresDirectInvocation>false</requiresDirectInv...
<requiresProject>true</requiresProject>
<requiresReports>false</requiresReports>
<aggregator>false</aggregator>
<requiresOnline>false</requiresOnline>
<inheritedByDefault>true</inheritedByDefault>
<phase>process-sources</phase>
<implementation>nu.mine.kino.plugins.MyMojo</imple...
<language>java</language>
<instantiationStrategy>per-lookup</instantiationSt...
<executionStrategy>once-per-session</executionStra...
<parameters>
<parameter>
<name>outputDirectory</name>
<type>java.io.File</type>
<required>true</required>
<editable>true</editable>
<description>Location of the file.</description>
</parameter>
</parameters>
<configuration>
<outputDirectory implementation="java.io.File">$...
</configuration>
</mojo>
</mojos>
<dependencies/>
</plugin>
-[[Mojoって何?>http://blog.goo.ne.jp/ikkoan/e/faee35340ce...
**所感 [#yf38b602]
、、、、、、これ、デバッグどうやるんだ??
**組み込みプロパティの一覧 [#r1207831]
-[[ParameterExpression>http://wiki.fdiary.net/maven2/?Par...
に一覧があります。感謝!
**関連リンク [#t80863c1]
-[[Your First Plugin>http://maven.apache.org/guides/plugi...
-[[Maven2のTipsを集めるWiki>http://wiki.fdiary.net/maven2...
-[[[Maven] Maven2 Plugin の作り方 >http://www.in-vitro.jp...
----
この記事は
#vote(おもしろかった[7],そうでもない[1])
- リポジトリ内の maven-metadata-local.xml に<prefix>hoge<...
- http://maven.apache.org/guides/plugin/guide-java-plugin...
#comment
#topicpath
SIZE(10){現在のアクセス:&counter;}
ページ名: