Add scala class to DataNucleus enhancer CLASSPATH

巧了我就是萌 提交于 2019-12-06 04:39:31

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!

Win Myo Htet

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

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