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" />
	<target name="antan">
		<javac srcdir="${src.dir}"
		    <compilerarg value="-proc:only"/>
			<classpath refid="classpath" />

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Share This

Share this post with your friends!