Search code examples
google-app-enginescaladatanucleusgae-eclipse-plugin

Add scala class to DataNucleus enhancer CLASSPATH


I am writing a Google App Engine web app and wish to use Scala on the server side. I'm using Eclipse and the Google App Engine plugin. However, as soon as I add an empty Scala class source file to my project, the DataNucleus enhancer warns:

SEVERE: Class "com.my.package.UserAccount" was not found in the CLASSPATH. Please check your specification and your CLASSPATH.

I will eventually get round to making the class persistent but I want to get rid of this error first.

So far I've added the Scala Nature, and have tried cleaning the project and also restarting Eclipse but I always get the same warning issued from the enhancer.

Any ideas on what I can do to get the enhancer to run successfully?


Solution

  • I've struggled away with this for the last few days. Class not found errors thrown by the datanucleus enhancer on Scala classes occur because the scala-library.jar file isn't in the classpath when the enhancer runs. I've found two solutions:

    1. Simple but cludgy: Copy scala-library.jar to the folder in eclipse/plugins which contains the enhancer. For me this is currently: /opt/eclipse/plugins/com.google.appengine.eclipse.sdkbundle_1.5.5.r36v201110112027/appengine-java-sdk-1.5.5/lib/tools/orm

    2. Switch off the enhancer builder in your project properties and create an ant file to run it manually. You can then properly control the classpath. I really struggled to get the scala-library into the classpath so gave up and copied it into the same folder as my datanucleus jars. My ant file if anyone's interested is:

    <project name="DataNucleusEnhancer" default="enhance" basedir="."> 
        <property name="base.dir" location="/home/steve/Projects/DNProject"/>
        <property name="datanucleus.libs" location="/home/steve/Projects/Jar Libraries/datanucleusjars"/>
        <property name="sdk.dir" location="/opt/eclipse/plugins/com.google.appengine.eclipse.sdkbundle_1.5.5.r36v201110112027/appengine-java-sdk-1.5.5"/>
        <property name="classes.dir" location="${base.dir}/war/WEB-INF/classes/"/>
        <property name="entities.dir" location="${base.dir}/war/WEB-INF/classes/packagenamehere/entities"/>
    
        <path id="enhancer.classpath">
            <fileset dir="${datanucleus.libs}" includes="*.jar" excludes="" />
            <fileset dir="${sdk.dir}/lib/user" includes="*.jar" />
        </path>
    
        <target name="enhance" description="DataNucleus enhancement">
            <taskdef name="datanucleusenhancer" classpathref="enhancer.classpath" classname="org.datanucleus.enhancer.tools.EnhancerTask" />
            <datanucleusenhancer dir="${classes.dir}" failonerror="true" verbose="true">
                <fileset dir="${entities.dir}" includes="**/*.class" />
                <classpath>
                <path location="${base.dir}/war/WEB-INF/classes/"/>
                    <path refid="enhancer.classpath"/>
                </classpath>
            </datanucleusenhancer>
        </target>
    
    </project>
    

    In testing I also found the enhancer unwilling to enhance classes if I had no namespaces. I'm also concerned that I now need to manage the copy of scala-library.jar to make sure it's the same as in the scala eclipse plugin. It'd be much better if the gae plugin worked properly!