用于检查源代码对特定 Java 版本的依赖性的工具
是否有一种快速方法(例如工具)可以从源代码(或者甚至从编译的类)检测应用程序的哪些部分调用仅在特定 Java 版本中实现的 Java API 方法? (例如,我的应用程序的哪些部分是特定于 Java6 的)
我不一定希望跳过所有 ClassMismatchErrors 并避免尝试错误方法。假设我只想记录应用程序的哪些部分如果是为 Java6 编写的,则无法工作,并且我想在 JDK 版本 5 中运行它。
有这样的事吗?谷歌这次没有帮助,我也没有在这里找到任何解决方案(确实是一种罕见的情况:)
Is there a quick way (e.g. tool) to detect, from the source (or maybe even from compiled classes), which parts of an application call Java API methods that are only implemented in a specific Java version? (e.g. which parts of my app are Java6-specific)
I don't necessarily want to hop through all ClassMismatchErrors and avoid the trial-and-error-method. Let's say I only want to document which parts of an application won't work if they were writte for, e.g., Java6 and I want to run it in a version 5 JDK.
Is there something like this? Google did not help this time, nor did I find any solution here (a rare case indeed:)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Animal Sniffer 可能对此有所帮助,尤其是它的 Maven 插件。
The Animal Sniffer might be helpful for this, especially its Maven plugin.
如果我理解正确的话,你所描述的对我来说听起来不是一个好主意。
听起来你想在 JDK 6 上构建一些库(指定 -target 1.5),但让它在 JDK 5 上运行,并且只是到处都有某些类或方法,这是行不通的(因为它们需要一个仅限 Java6 的 API) 。我不会这样做。 应该工作的方法可能仍然会触发加载一个类,该类本身包含一些对Java 6中新类的引用,以及一个
错误
将被抛出。如果您只选择哪个版本是您的最低支持版本并接受它,那就更好了。
If I understand you correctly, what you're describing doesn't sound like a very good idea to me.
It sounds like you want to build some library on JDK 6 (specifying -target 1.5), but let it be run on JDK 5 and just have certain classes or methods here and there just not work (because they needed a Java6-only API). I wouldn't do this. A method which should work might still trigger a class to be loaded which itself contains some reference to a class that's new in Java 6, and an
Error
will be thrown.It's much better if you just choose which version is your minimum supported version and live with that.