Sunday, December 3, 2017

Eclipse JDO and MySQL Integration using Ant

Eclipse JDO and MySQL Integration using Ant


I did it in a Linux machine( Ubuntu 10.10 ).I am assuming the following programs are already installed in the machine.

Eclipse JAVA IDE
MySQL

DataNucleus is used as an implementation for JDO( Java Data Object ). Follow the link and download
datanucleus-accessplatform-rdbms-<version>.zip from the latest release (and extarct) . I worked with version= 3.1.0-release.

Also download JDO-API from apache. Find the Latest version and download jdo-api-<jdo-version>.jar.
MySQL JDBC driver is also needed. 

Now create a Java Project in Eclipse and add the following jars to the projects CLASSPATH.

From ....../datanucleus-accessplatform-rdbms-<version>/dep/ folder
       asm-<asm-version>.jar
       log4j-<log4j-version>.jar

From ....../datanucleus-accessplatform-rdbms-<version>/lib/ folder
       datanucleus-api-jdo-<version>.jar
       datanucleus-core-<version>.jar
       datanucleus-enhancer-<version>.jar
       datanucleus-rdbms-<version>.jar

....../jdo-api-<jdo-version>.jar
....../mysql-connector-java-<mysql-version>-bin.jar (For MySQL JDBC driver).

Now Export the created Java project to General > AntBuildFiles . Click next and finish nothing much is needed to be done. A build.xml file has been created in the projects root directory. Open it with Eclipse Ide.

Add following snippet of xml to it

<target
name="-post-compile"
depends="init" >

<taskdef
name="datanucleusenhancer"
classname="org.datanucleus.enhancer.tools.EnhancerTask"
classpathref="<ProjectName>.classpath" />

<echo message="start datanucleusenhancer" />

<datanucleusenhancer
classpathref="<ProjectName>.classpath"
dir="bin"
verbose="true" >

<fileset dir="bin" >

<include name="**/*.class" />
</fileset>
</datanucleusenhancer>

<echo message="end datanucleusenhancer" /> 
</target>  

add this under <project> tag . Change <ProjectName>  according to yours.

Find <javac> tag and add the following line inside <javac></javac> tag.
<compilerarg line=" -processor org.datanucleus.enhancer.EnhancerProcessor" />
Add an attribute verbose="on" to javac tag.

Now find the following xml

<target
name="build"
depends="build-subprojects,build-project"/>


Turn it to
<target
name="build"
depends="build-subprojects,build-project,-post-compile" />


Now go to project --- properties -- builders and select new. Then select "Ant Builder" . Add a name and in "Buildfile" tab point the build.xml file. Mark only the newly created builder in the "Builders" list.



go to link download

No comments:

Post a Comment