// 下階層用テンプレート #topicpath ---- //ここにコンテンツを記述します。 #contents **プラグイン用Eclipseプロジェクトを作る [#z8b8ef14] mvn archetype:create -DgroupId=nu.mine.kino.plugins \ -DartifactId=maven-hoge-plugin \ -DarchetypeArtifactId=maven-archetype-mojo 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 file " + touch, e); } finally { if (w != null) { try { w.close(); } catch (IOException e) { // ignore } } } } } **Mavenコマンドでローカルリポジトリにプラグインをインストールする [#s9e102f1] maven clean install これで先のソースがローカルリポジトリにインストールされました。 **Mavenプロジェクトからインストールしたプラグインを呼び出す。 [#ud172144] さて、ローカルリポジトリにプラグインがインストールされたので、別の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:touch 引数の意味。 mvn [groupId]:[artifactId]:[version]:[ゴール名] なんだろ、ローカルにインストールされているだけなので、グループIDとかを指定しなくてはいけないのかな。 **所感 [#yf38b602] 、、、、、、これ、デバッグどうやるんだ?? **関連リンク [#t80863c1] -[[Your First Plugin>http://maven.apache.org/guides/plugin/guide-java-plugin-development.html]] -[[Maven2のTipsを集めるWiki>http://wiki.fdiary.net/maven2/?CookBook#l5]] -[[[Maven] Maven2 Plugin の作り方 >http://www.in-vitro.jp/blog/index.cgi/Maven/20051024_01.html]] ---- この記事は #vote(おもしろかった,そうでもない) #comment #topicpath SIZE(10){現在のアクセス:&counter;}