JPA 2 MetaModel Generator using Ant

In my previous article I have explained how to generate metamodel using your Eclipse IDE. However, in most scenarios you will have to create from your build scripts. This tutorial explains how to add this option in your ant script. For the detailed explanation on project example code, please refer the previous post. Here I explain only the build script.

Java Persistence API (JPA)

JPA 2 MetaModel Generator Using Ant Script

In the below script, compiler argument -proc:only, tells that only to process the meta annotated classes.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="antan" name="Annotation">
	<property environment="env" />
	<property name="target" value="1.6" />
	<property name="source" value="1.6" />
	<property name="src.dir" value="${basedir}/src" />
	<property name="target.dir" value="${basedir}/target" />
	<property name="src.lib" location="${basedir}" />
	<path id="classpath">
		<fileset dir="${src.lib}">
			<include name="*.jar" />
		</fileset>
	</path>
	<target name="antan">
		<javac srcdir="${src.dir}"
		    destdir="${target.dir}"
		    failonerror="false"
		    fork="true">
		    <compilerarg value="-proc:only"/>
			<classpath refid="classpath" />
		</javac>
	</target>
</project>

Project Structure

The files are generated to “target” folder in your project.

JPA MetaModel Ant

Hope this helps. You can just use the above script for generating the metamodel for your JPA projects.

Comments

comments

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Speak Your Mind

*

Close
Please support the site
By clicking any of these buttons you help our site to get better