Posts Tagged AppEngine
Grails and Google AppEngine on Windows
Posted by Morten in Uncategorized on July 27, 2009
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.
Version 1.2.2 of the Google AppEngine JavaSDK Released
Posted by Morten in Uncategorized on July 27, 2009
There is a new version of the Google AppEngine SDK for Java.
Version 1.2.2.
The release notes are available here.
Grails and Google AppEngine
Posted by Morten in Uncategorized on July 14, 2009
I suggest a temporary fix to the described problems here.
I’m porting my Grails project from Mor.ph to Google AppEngine. If your using Windows certain things will not work out of the box.
To be able to use GORM you need to install the GORM-JPA plugin. Now you should in theory be able to use the GORM dynamic functions.
Alas however installing the GORM-JPA plugin will make the packaging functions for Google AppEngine fail. Google has a step in the deployment process where they enhance the byte-code to allow storage in their storage solution.
You run into this error
... java.io.IOException: CreateProcess: ...
Windows can only support command-lines with a length of 8191. The enhancement step reaches this limit when enhancing Grails applications. The Eclipse plugin has this issue mentioned here.
I’ve tried the following workarounds, with no luck:
- Running the packaging step in Powershell, hoping that powershell doesn’t have this limit.
- Running the packaging step in Cygwin, hoping that the linux emulation would work around the process execution limit.
Currently I’m working on rewriting the ant macro for the enhancement step in Google’s SDK. There are some improvements that can be done.
This is what the macro looks like in ant-macros.xml
<!--
A macrodef for ORM enhancement for a war. Use like:
<enhance_war war="${war}"/>
-->
<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>
Notice that the class path argument contains a fileset of the lib directories. This can be changed to just include the path element, since Java will resolve the .jar files.
The second part of the problem is the argument fileset list
<fileset dir="@{war}/WEB-INF/classes" includes="**/*.class"/>
Grails creates a lot of class files, so just fixing the class path will not fix the command line problem. Ive been working on excluding files that do not need enhancement, such as the app-engine plugin classes themselves. Another idea is to move the domain into its own package, thus its own directory. This however leads to issues with naming, apparently the compiled groovy classes are not named according to how Datanucleus would like it.
I tried using the Datanucleus tool directly without success.
The latest Idea I have is to somehow wrap into the compilation step of the grails war target and do the enhancement there, and turn the enhancement step off when using just the app-engine plugin.