Hibernate と maven2
Hibernate3-maven-pluginっていうのもあるらしいけど、まだちゃんと公開されてないので、hibernatetoolのAntタスクを呼び出すpom.xmlの書き方。
The one problem I ran into was generating the database schema form the source code using hibernatetool. Hibernatetool works great but using it from Maven was a little bit more work. There is a Hibernate3-maven-plugin available at codehaus, but that plugin isn't available in a public repository (you can get the source and build it your self, but that didn't seem like a good idea for this situation). To get around the plugin not being available, I used the Maven maven-antrun-plugin. Here is how I added schema generation to my Maven build:
追記
上のサイトに書かれているものをそのままbuild/puluginsに追加しても動かなかった。
まず、
required artifacts missing: javax.persistence:ejb:jar:3.0-public-draft-20060118 for the artifact: org.apache.maven.plugins:maven-antrun-plugin:maven-plugin:1.1
というメッセージが出たので、リポジトリを見てみたら ejb-3.0-public-draft-20060118.pomにはこう書いてあった。
<project> <modelVersion>4.0.0</modelVersion> <groupId>javax.persistence</groupId> <artifactId>ejb</artifactId> <version>3.0-public-draft-20060118</version> <url>http://www.jcp.org/en/jsr/detail?id=220</url> <distributionManagement> <downloadUrl>http://prdownloads.sourceforge.net/hibernate/hibernate-annotations-3.1beta8.tar.gz?download</downloadUrl> </distributionManagement> </project>
っつうわけで、http://prdownloads.sourceforge.net/hibernate/hibernate-annotations-3.1beta8.tar.gz?download の中のlibから、ejb3-persistence.jarを取り出して、pomのディレクトリにコピーしてリネーム。
これでantタスクが動くようになるけど、今度はlog4jのクラスがないって怒られるので、追加したpluginの定義内にdependencyを追加。
<dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.9</version> </dependency>
これで
mvn process-classes -Dexport=false
って実行するとddlが出力されます。