缺少model.jar(model / error / Error.class)所需的依赖项“class javax.jdo.spi.PersistenceCapable $ ObjectIdFieldSupplier”

时间:2010-07-16 17:01:48

标签: java scala jdo

在针对使用JDO增强的Java模型编译有效代码时出现编译错误。我对错误感到困惑,因为没有直接使用Scala中的包私有静态成员接口。我知道Scala不支持使用Scala代码中的这些接口,但我很困惑Scala编译器会抱怨它们。

以下是我遇到的错误:

[scalac] Compiling 3 scala and 196 java source files to /home/alain/Documents/Project/build/model/src
[scalac] error: error while loading Error, Missing dependency 'class javax.jdo.spi.PersistenceCapable$ObjectIdFieldSupplier', required by /home/alain/Documents/Project/model/dist/model.jar(model/error/Error.class)
[scalac] error: error while loading Binder, Missing dependency 'class javax.jdo.spi.PersistenceCapable$ObjectIdFieldSupplier', required by /home/alain/Documents/Project/model/dist/model.jar(model/attachment/Binder.class)
[scalac] error: error while loading Journal, Missing dependency 'class javax.jdo.spi.PersistenceCapable$ObjectIdFieldSupplier', required by /home/alain/Documents/Project/model/dist/model.jar(model/note/Journal.class)
[scalac] error: error while loading Exemption, Missing dependency 'class javax.jdo.spi.PersistenceCapable$ObjectIdFieldSupplier', required by /home/alain/Documents/Project/model/dist/model.jar(model/exemption/Exemption.class)
[scalac] error: error while loading Flag, Missing dependency 'class javax.jdo.spi.PersistenceCapable$ObjectIdFieldSupplier', required by /home/alain/Documents/Project/model/dist/model.jar(model/flag/Flag.class)
[scalac] error: error while loading ConfigurationGroup, Missing dependency 'class javax.jdo.spi.PersistenceCapable$ObjectIdFieldSupplier', required by /home/alain/Documents/Project/model/dist/model.jar(model/configuration/ConfigurationGroup.class)
[scalac] error: error while loading IssueConfiguration, Missing dependency 'class javax.jdo.spi.PersistenceCapable$ObjectIdFieldSupplier', required by /home/alain/Documents/Project/model/dist/model.jar(model/analysis/configuration/IssueConfiguration.class)
[scalac] 7 errors found

这是我用来编译的Ant片段:

<target name="compile" depends="jar">
    <depend srcdir="src" destdir="${src.classes.dir}" cache="${build.dir}/src_dependencies" />
    <scalac srcdir="src" destdir="${src.classes.dir}" classpathref="src.build.classpath">
        <include name="**/*.scala"/>
        <include name="**/*.java"/>
    </scalac>
    <javac srcdir="src" destdir="${src.classes.dir}" source="1.6" target="1.6" nowarn="on"
       debug="on" encoding="UTF-8" classpathref="src.build.classpath" />
</target>

带有增强类的model.jar位于src.build.classpath。

我不明白为什么scalac会关心Java类的依赖关系,如果它们不影响编译我的Scala源代码的知识就无法解决。

有趣的是,IntelliJ的Scala插件能够编译和运行此代码。

1 个答案:

答案 0 :(得分:1)

将增强的代码保留在scalac构建类路径之外。您仍然需要未加强的代码才能编译。

以下是我解决这个问题的方法:

  1. 将常规JAR名称更改为model-api.jar(继承目标使用src.classes.dir)

  2. 我在src.build.classpath

  3. 中使用model-api.jar而不是model.jar构建了依赖项

    以下是增强目标的摘要:

    <property name="production.enhanced.dir" value="${production.classes.dir}/../enhanced" />
    <copy todir="${production.enhanced.dir}">
        <fileset dir="${production.classes.dir}" />
    </copy>
    <jdodoclet ...>
    <jdoc ...>
    <jar destfile="dist/model.jar"> <fileset dir="${production.enhanced.dir}" />
        <fileset dir="src" excludes="**/*.java */.jj */.scala */.groovy" />
    </jar>
    

    我必须做的值得注意的版本是将未增强的类复制到沙箱目录,在沙箱目录上运行JDO增强并生成具有原始名称的运行时JAR。