Showing posts with label maven. Show all posts
Showing posts with label maven. Show all posts

Thursday, March 12, 2009

Hibernate bytecode instrumentation (enhance persistent classes) with help of Maven

Is used to enable Hibernate lazy property fetching. "**/model/*" are your persistent classes.

pom.xml:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>Instrument domain classes</id>
<configuration>
<tasks>
<taskdef name="instrument"
classname="org.hibernate.tool.instrument.cglib.InstrumentTask">
<classpath>
<path refid="maven.dependency.classpath"/>
<path refid="maven.plugin.classpath"/>
</classpath>
</taskdef>
<instrument verbose="true">
<fileset dir="${project.build.outputDirectory}">
<include name="**/model/*.class"/>
</fileset>
</instrument>
</tasks>
</configuration>
<phase>process-classes</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.6.ga</version>
</dependency>
</dependencies>
</plugin>

Hibernate ddl (database schema) generation with help of Maven

pom.xml:
<plugin>
<!-- hibernate ddl generation -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.0-alpha-2</version>
<configuration>
<components>
<component>
<name>hbm2ddl</name>
<outputDirectory>.</outputDirectory>
</component>
</components>
<componentProperties>
<configurationfile>src/main/db/hibernate.cfg.xml</configurationfile>
<drop>false</drop>
<create>true</create>
<export>false</export>
<jdk5>true</jdk5>
<format>true</format>
</componentProperties>
</configuration>
<executions>
<execution>
<id>export-mysql</id>
<phase>process-classes</phase>
<goals>
<goal>hbm2ddl</goal>
</goals>
<configuration>
<componentProperties>
<propertyfile>src/main/db/hibernate-mysql.properties</propertyfile>
<outputfilename>target/mysql-ddl.sql</outputfilename>
</componentProperties>
</configuration>
</execution>
</executions>
</plugin>

hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!--Annotated classes-->
<mapping class="com.etymgiko.lyricscollection.model.Artist" />
<mapping class="com.etymgiko.lyricscollection.model.Song" />
</session-factory>
</hibernate-configuration>

hibernate-mysql.properties:
# This properties file defines the dialect for the MYSQL database
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect

Monday, March 2, 2009

Maven compile sources version 1.5

Add following to pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>

Sunday, March 1, 2009

Maven artifact sources

Download sources of artifacts (from pom.xml) to local repository.

set JAVA_HOME=C:\jdk1.6.0
set MAVEN_HOME=D:\java\apache-maven-2.0.9
%MAVEN_HOME%\bin\mvn dependency:sources

Wednesday, February 25, 2009

Maven dependency tree

set JAVA_HOME=C:\jdk1.6.0
set MAVEN_HOME=D:\java\apache-maven-2.0.9
%MAVEN_HOME%\bin\mvn dependency:tree > dep.txt

Followers