Scala类文件破坏了Java jar的错误 [英] Scala class file broken error over Java jar

查看:138
本文介绍了Scala类文件破坏了Java jar的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个编译错误:

[warn] com.google.api.client.auth.oauth2.Credential类不是发现 - 继续存根。
[错误]加载GoogleService时出错,类文件'...... / gdata-core-1.0.jar(com / google / gdata / client / GoogleService.class)'中断



我发现这个类似的问题,但无法成功使用其解决方案为我的情况。如何跟踪Scala编译器中实际破坏的内容(即获取实际破坏的细节),以确定解决方案是否适合?



我认为这个Google jar的源代码来自这里<注意:不像其他问题,在我的情况下,谷歌罐子被包括在我的项目中的非托管,在 LIB 目录中,按这些谷歌的设置说明

正如链接答案中所述,当类包含一些不是在类路径中存在更长的时间。 Java认为这是可以接受的,但Scala没有。通常只会遇到严重优化的java库,他们故意排除不必要的注释。谷歌为他们的许多代码做了这件事;非常诚实,我不认为我在任何非谷歌库中都看到过这个问题。



实用的解决方案是使用高级搜索>找到包含缺失类的jar。如果gdata-core是用maven构建的(现在是最严肃的java库),可以很容易地从< dependencies> 部分看到 pom.xml 哪些依赖关系被声明为可选的,因此找出这类类路径可能出现的问题。不幸的是,这个特定的库仍然使用ant构建,所以很难确定构建类路径而不读取整个 build.xml 并手工计算出来。


I have run into a compilation error:

[warn] Class com.google.api.client.auth.oauth2.Credential not found - continuing with a stub. [error] error while loading GoogleService, class file '....../gdata-core-1.0.jar(com/google/gdata/client/GoogleService.class)' is broken

I found this similar question but couldn't successfully use its solution for my case. How can I trace what's actually broken in this jar as per the Scala compiler (i.e. get the details of what's actually broken), to make sure what the solution aught to be?

The source where I think this Google jar builds from, is here.

Note: unlike the other questions, in my case, the google jars are included unmanaged in my project, in the lib directory, as per these google setup instructions.

解决方案

As described in your linked answer, this error happens when a class contains some annotations which are no longer present on the classpath. Java considers this acceptable, but Scala does not. You'll generally only run into this problem with heavily optimized java libraries where they've deliberately excluded the "unnecessary" annotations. Google does this for a lot of their code; to be perfectly honest I don't think I've ever seen the problem in any non-google libraries.

The pragmatic solution is to use advanced search on maven central to find the jar that contains the missing class. If gdata-core had been built with maven (as most serious java libraries are these days), it would be easy to see from the <dependencies> section of pom.xml which dependencies had been declared optional, and therefore figure out where any classpath problems of this kind were likely to be. Unfortunately this particular library is still built with ant, so it's hard to determine the build classpath without reading the whole build.xml and figuring it out "by hand".

这篇关于Scala类文件破坏了Java jar的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆