Tuesday, August 26, 2008

More on Maven

Well if you don't really like ant for some reason

Quick Facts


Adding Plugin to Project

Add the following to your POM


<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<hibernate>
<configurationFile>
src/main/resources/hibernate.cfg.xml
</configurationFile>
</hibernate>
<outputDirectory>
<hbm2cfgxml>src/main/resources</hbm2cfgxml>
</outputDirectory>
<componentProperties>
<outputfilename>schema.sql</outputfilename>
</componentProperties>
</configuration>
<dependencies>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
</dependencies>
</plugin>
<plugin>


Adding Extensions

This is requiered to ensure the correct driver for the databse you are using is available to the plugin. I am using MySQL for example for other databses you have to mention there respective driver jar.


<build>

........

<extensions>

<extension>

<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.0.8</version>

</extension>

</extensions>

</build>


Plugin Goals

  • hibernate3:hbmtemplate Generic exporter that can be controlled by a user provided template or class.
  • hibernate3:hbm2cfgxml Generates hibernate.cfg.xml
  • hibernate3:hbm2dao Base class for the different hibernate3 goals based on the Ant tasks of hibernate tools.
  • hibernate3:hbm2ddl Generates database schema.
  • hibernate3:hbm2doc Generates HTML documentation for the database schema.
  • hibernate3:hbm2hbmxml Generates a set of hbm.xml files.
  • hibernate3:hbm2java Generates Java classes from set of *.hbm.xml files.

Usage

Run the following command from command line(ensure you use the complete plugin name)

mvn org.codehaus.mojo:hibernate3-maven-plugin:2.1:hbm2ddl

No comments: