缺少 model.jar(model/error/Error.class) 所需的依赖项“class javax.jdo.spi.PersistenceCapable$ObjectIdFieldSupplier”
针对使用 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 插件能够编译并运行此代码。
I get compile errors when compiling valid code against a Java model enhanced with JDO. I am confused at the errors because there is no direct usage of the package private static member interfaces in question from Scala. I understand Scala doesn't support using such interfaces from Scala code, but I am confused that the Scala compiler complains about them.
Here is the error I am getting:
[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
Here is the Ant snippet I use to compile:
<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 with the enhanced classes is on src.build.classpath.
I don't understand why scalac cares about dependencies of Java classes it can't resolve if they don't affect the knowledge to compile my Scala source.
Interestingly IntelliJ's Scala Plug-in is able to compile and run this code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将增强的代码保留在 scalac 构建类路径之外。不过,您仍然需要未增强的代码才能进行编译。
以下是我解决此问题的方法:
将常规 JAR 名称更改为 model-api.jar(继承的目标使用 src.classes.dir)
我在
src.build.classpath
中使用 model-api.jar 而不是 model.jar 来构建依赖项以下是增强目标的摘要:
我必须制作的值得注意的版本是将未增强的类复制到沙箱目录,运行沙箱目录上的 JDO 增强并生成具有原始名称的运行时 JAR。
Keep the enhanced code out of the scalac build classpath. You will still need the unenhanced code in order to compile though.
Here is how I solved this:
Alter the regular JAR name to model-api.jar (inherited target uses src.classes.dir)
I made the build of dependencies use model-api.jar instead of model.jar in
src.build.classpath
Here is a summary of the enhance target:
The notable editions I had to make were copying the unenhanced classes to an sandbox directory, running the JDO enhancement on the sandbox directory and producing a runtime JAR with the original name.