在DataNucleus增强器CLASSPATH中添加scala类



我正在编写一个Google App Engine web应用程序,希望在服务器端使用Scala。我正在使用Eclipse和谷歌应用引擎插件。然而,只要我将一个空的Scala类源文件添加到项目中,DataNucleus增强器就会发出警告:

SEVERE: Class "com.my.package. exe "中未找到"UserAccount"类路径中。请检查您的规格和CLASSPATH。

我最终会设法使类持久,但我想首先消除这个错误。

到目前为止,我已经添加了Scala Nature,并尝试清理项目并重新启动Eclipse,但我总是从增强器发出相同的警告。

我能做些什么来让增强器成功运行吗?

在过去的几天里,我一直在努力解决这个问题。由于Scala增强器运行时Scala -library.jar文件不在类路径中,因此会发生由datanucleus增强器在Scala类上抛出的类未找到错误。我找到了两个解决方案:

  1. 简单但模糊:将scala-library.jar复制到eclipse/plugins中包含增强器的文件夹中。对我来说,目前是:/opt/eclipse/plugins/com.google.appengine.eclipse.sdkbundle_1.5.5.r36v201110112027/appengine-java-sdk-1.5.5/lib/tools/orm

  2. 关闭项目属性中的增强器构建器,并创建一个ant文件以手动运行它。然后,您可以正确地控制类路径。我真的很难将scala库放入类路径中,所以放弃了,并将其复制到与datanucleus jar相同的文件夹中。如果有人感兴趣,我的ant文件是:

<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>

在测试中,我还发现如果没有名称空间,增强程序不愿意增强类。我还担心我现在需要管理scala-library.jar的副本,以确保它与scala eclipse插件中的副本相同。如果gae插件能正常工作就好了!

我尝试了steve回答的选项1,将scala-library.jar放到eclipse插件文件夹中。这个问题还没有解决。然后将scala-library.jar放到PROJECT/war/WEB-INF/lib/中,并将其添加到Build Path中。它的工作原理!所以我撤销steve回答的选项1,从eclipse插件文件夹中删除scala-library.jar并重新启动eclipse。我又试了一次,它仍然有效!我使用的是eclipse 2.7.1, scala 2.9.1和scala-ide 2.0.0

最新更新