In a previous post I described a problem where the app-engine command would fail when enhancing the domain objects for persistence.

The problem was that the command line became too long to execute on windows, when executing the enhancement task.

I’ve been working on several workarounds for this problem.

  • Enhancing the classes during compilation
  • Enhancing the classes manually
  • Enhancing the classes programmatically
  • Modifying the ant target to produce shorter command line calls

Enhancing during compilation

Make sure you have version JDK 1.6 and add the enhancer and its requirements to the compilation class-path. Produces no errors during compilation, but no enhancement is done. Fails when not all libraries included, so something is happening. I’m not sure it can find the persistence.xml file to use.

Enhancing the classes manually

I had problems where the enhancer wouldn’t find the domain objects when compiled into a package. It would say that the classes we’re not included in my class-path, even though they were.

However, working with the manual enhancement I found a wonderful option called checkonly. So you could set the enhancement tool to just check if the classes are enhanced. This would be a excellent extra option for the grails app-engine plug-in, if you could call grails app-engine diagnostic and see which files that are enhanced.

Enhancing the classes programmatically

This seems to be a viable option. I modified the app-engine plugin for grails to do the enhancement programmatically, however it failed to enhance the files with two problems. Out of the box, the persistance.xml file is not located where it should be to enhance the compiled classes. It must be copied to a location where the enhancer can find it. The other problem was that of how grails organizes its compiled files.

Modifying the ant target to produce shorter command line calls

This is what I’ve got working right now. In the Google SDK I modify the ant-macros.xml

<macrodef name="enhance_war" description="Run the ORM enhancer on an exploded war">
 <attribute name="war" description="The exploded war directory containing the application"/>
 <element name="args" optional="true" description="Additional arguments to the enhancer"/>
 <sequential>
 <enhance failonerror="true" >
 <args/>
 <classpath>
 <pathelement path="${appengine.tools.classpath}"/>
 <pathelement path="@{war}/WEB-INF/classes"/>
 <fileset dir="@{war}/WEB-INF/lib" includes="*.jar"/>
 </classpath>
 <fileset dir="@{war}/WEB-INF/classes" includes="**/*.class"/>
 </enhance>
 </sequential>
 </macrodef>

becomes

<macrodef name="enhance_war" description="Run the ORM enhancer on an exploded war">
 <attribute name="war" description="The exploded war directory containing the application"/>
 <element name="args" optional="true" description="Additional arguments to the enhancer"/>
 <sequential>
 <enhance failonerror="true" >
 <args/>
 <classpath>
 <pathelement path="${appengine.tools.classpath}"/>
 <pathelement path="@{war}/WEB-INF/classes"/>
 <fileset dir="@{war}/WEB-INF/lib" includes="*.jar"/>
 </classpath>
 <fileset dir="@{war}/WEB-INF/classes/persisted" includes="**/*.class"/>
 </enhance>
 </sequential>
 </macrodef>

Now all my domain classes that requires persistence is in a package called persisted.  The macro should be modified to fit your needs or find a convention to follow in all your projects running on Google AppEngine.

Bookmark and Share