I’m using maven with hibernate3 plugin to generate the sql code for my database schema/tables. I do so with the following configuration.
Also make sure you declare your driver in the plugin dependencies to be sure the driver can be loaded in the plugin. Otherwise you might get some JDBC exceptions.
Command line example:
mvn clean compile hibernate3:hbm2ddl |
Command line example:
mvn clean compile hibernate3:hbm2ddl
<!--
Hibernate 3 Plugin, used for schema creation
Usage example: mvn clean compile hibernate3:hbm2ddl
-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.0-alpha-2</version>
<configuration>
<components>
<component>
<name>hbm2ddl</name>
<implementation>annotationconfiguration</implementation>
</component>
</components>
<componentProperties>
<!-- Create Drop Statements -->
<drop>false</drop>
<!-- Enable Annotations -->
<jdk5>true</jdk5>
<!-- Define Database Properties to Use -->
<propertyfile>target/classes/database.properties</propertyfile>
<!-- Pretty Format SQL Code -->
<format>true</format>
<!-- Create tables automatically? -->
<export>false</export>
<!-- Output filename -->
<outputfilename>schema.sql</outputfilename>
</componentProperties>
</configuration>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>${oracle-driver.version}</version>
</dependency>
</dependencies> |
<!--
Hibernate 3 Plugin, used for schema creation
Usage example: mvn clean compile hibernate3:hbm2ddl
-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.0-alpha-2</version>
<configuration>
<components>
<component>
<name>hbm2ddl</name>
<implementation>annotationconfiguration</implementation>
</component>
</components>
<componentProperties>
<!-- Create Drop Statements -->
<drop>false</drop>
<!-- Enable Annotations -->
<jdk5>true</jdk5>
<!-- Define Database Properties to Use -->
<propertyfile>target/classes/database.properties</propertyfile>
<!-- Pretty Format SQL Code -->
<format>true</format>
<!-- Create tables automatically? -->
<export>false</export>
<!-- Output filename -->
<outputfilename>schema.sql</outputfilename>
</componentProperties>
</configuration>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>${oracle-driver.version}</version>
</dependency>
</dependencies>
Below is a short snippet I use to launch hsqldb automatically for unit testing in my java projects.
Biggest limitation to the exec-maven-plugin is that it can’t run processes asynchronous. This way a running application is blocking the maven process flow. A big limitation. I think they should add an option to be able to run the process in a separate process without blocking the flow if needed.
Below is the snippet, I tried to use the windows start command. But it didn’t really work.
<!-- Execute plugin to launch hsqldb -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<!--
start java
-cp "c:/Documents and Settings/%USERNAME%/.m2/repository/hsqldb/hsqldb/1.8.0.7/hsqldb-1.8.0.7.jar"
org.hsqldb.Server
-database.0 mydb
-dbname.0 xdb -->
<!-- use start to execute in separate thread -->
<executable>start</executable>
<!-- optional -->
<workingDirectory>/hsqldb</workingDirectory>
<arguments>
<argument>java</argument>
<argument>-cp</argument>
<argument>"C:/Documents and Settings/%USERNAME%/.m2/repository/hsqldb/hsqldb/1.8.0.7/hsqldb-1.8.0.7.jar"</argument>
<argument>org.hsqldb.Server</argument>
<argument>-database.0</argument>
<argument>mydb</argument>
<argument>-dbname.0</argument>
<argument>xdb</argument>
</arguments>
</configuration>
<dependencies>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.7</version>
</dependency>
</dependencies>
</plugin> |
<!-- Execute plugin to launch hsqldb -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<!--
start java
-cp "c:/Documents and Settings/%USERNAME%/.m2/repository/hsqldb/hsqldb/1.8.0.7/hsqldb-1.8.0.7.jar"
org.hsqldb.Server
-database.0 mydb
-dbname.0 xdb -->
<!-- use start to execute in separate thread -->
<executable>start</executable>
<!-- optional -->
<workingDirectory>/hsqldb</workingDirectory>
<arguments>
<argument>java</argument>
<argument>-cp</argument>
<argument>"C:/Documents and Settings/%USERNAME%/.m2/repository/hsqldb/hsqldb/1.8.0.7/hsqldb-1.8.0.7.jar"</argument>
<argument>org.hsqldb.Server</argument>
<argument>-database.0</argument>
<argument>mydb</argument>
<argument>-dbname.0</argument>
<argument>xdb</argument>
</arguments>
</configuration>
<dependencies>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.7</version>
</dependency>
</dependencies>
</plugin>
When building some Java projects with maven you might run into some missing Sun jars/artifacts.
[INFO] Failed to resolve artifact.
Missing:----------
1) javax.transaction:jta:jar:1.0.1B |
[INFO] Failed to resolve artifact.
Missing:----------
1) javax.transaction:jta:jar:1.0.1B
Luckily you can fix this. 🙂
Go to the Java site and grab the jta-1_0_1B-classes.zip file.
Then manually import the file into your local maven repository by running the following command:
mvn install:install-file -Dfile=jta-1_0_1B-classes.zip -DgroupId=javax.transaction -DartifactId=jta -Dversion=1.0.1B -Dpackaging=jar |
mvn install:install-file -Dfile=jta-1_0_1B-classes.zip -DgroupId=javax.transaction -DartifactId=jta -Dversion=1.0.1B -Dpackaging=jar
Now you have it. If you wish you can add this dependency to your pom.xml manually now also.
<dependency>
<groupid>javax.transaction</groupid>
<artifactid>jta</artifactid>
<version>1.0.1B</version>
</dependency> |
<dependency>
<groupid>javax.transaction</groupid>
<artifactid>jta</artifactid>
<version>1.0.1B</version>
</dependency>
For more information look at maven’s mini-howto.