Add scala class to DataNucleus enhancer CLASSPATH

末鹿安然 提交于 2020-01-02 13:04:11

问题


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?


回答1:


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!




回答2:


I tried the option 1 of steve's answer dropping the scala-library.jar in the eclipse plugin folder. It is still not solving yet. I then drop scala-library.jar in PROJECT/war/WEB-INF/lib/ and add it to Build Path. It works! So I undo option 1 of steve's answer by removing the scala-library.jar from the eclipse plugin folder and restart the eclipse. I try again and it still works! I am using eclipse 2.7.1, scala 2.9.1 and scala-ide 2.0.0



来源:https://stackoverflow.com/questions/8013391/add-scala-class-to-datanucleus-enhancer-classpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!