对于同一个 jar 文件,为什么我的 javap 输出与你的不同?
我在编译依赖于 jline-0.9.94 的 Maven 代码时遇到问题。具体来说,我正在使用 Groovy 1.7.6 进行编译它的默认 Ant 目标并出现以下错误:
[...]
-banner:
[echo] Java Runtime Environment version: 1.6.0_22
[echo] Java Runtime Environment vendor: Apple Inc.
[echo] Ant version: Apache Ant version 1.7.1 compiled on June 27 2008
[echo] Operating system name: Mac OS X
[echo] Operating system architecture: x86_64
[echo] Operating system version: 10.6.6
[echo] Base directory: /Users/ldhanson2/tmp/groovy-1.7.6
[echo] Java Home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
[...]
-stagedcompile-groovy:
[groovyc] Compiling 166 source files to /Users/ldhanson2/tmp/groovy-1.7.6/target/classes
[groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
[groovyc] Compile error during compilation with javac.
[groovyc] /Users/ldhanson2/tmp/groovy-1.7.6/src/main/groovy/ui/InteractiveShell.java:222: cannot find symbol
[groovyc] symbol : method setDefaultPrompt(java.lang.String)
[groovyc] location: class jline.ConsoleReader
[groovyc] reader.setDefaultPrompt("groovy> ");
[groovyc] ^
jline 依赖项已正确解析,但奇怪的是,jar 中似乎不存在 setDefaultPrompt 方法:
$ javap -classpath target/lib/compile/jline-0.9.94.jar jline.ConsoleReader | grep setDefaultPrompt
$
(javap 输出中似乎也缺少其他方法,但 setDefaultPrompt 是破坏该方法的方法我的构建。)
我尝试从本地 Maven 存储库中清除 jline 并重试,但无济于事。我还检查了 Maven Central 中的 jline jarfile 以及具有相同结果的镜像。
奇怪的是,我可以将 jar 文件复制到另一台机器(Sun)并执行完全相同的步骤,并且我在 jar 文件中看到了预期的 setDefaultPrompt 方法。其他人也在 Mac 上成功执行了相同的步骤。
我的机器上可能发生什么情况会阻止 Java 工具链查看 jar 文件中包含的方法?
I'm having trouble compiling code which has a maven dependency on jline-0.9.94. Specifically, I'm compiling Groovy 1.7.6 using its default Ant target and getting the following error:
[...]
-banner:
[echo] Java Runtime Environment version: 1.6.0_22
[echo] Java Runtime Environment vendor: Apple Inc.
[echo] Ant version: Apache Ant version 1.7.1 compiled on June 27 2008
[echo] Operating system name: Mac OS X
[echo] Operating system architecture: x86_64
[echo] Operating system version: 10.6.6
[echo] Base directory: /Users/ldhanson2/tmp/groovy-1.7.6
[echo] Java Home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
[...]
-stagedcompile-groovy:
[groovyc] Compiling 166 source files to /Users/ldhanson2/tmp/groovy-1.7.6/target/classes
[groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
[groovyc] Compile error during compilation with javac.
[groovyc] /Users/ldhanson2/tmp/groovy-1.7.6/src/main/groovy/ui/InteractiveShell.java:222: cannot find symbol
[groovyc] symbol : method setDefaultPrompt(java.lang.String)
[groovyc] location: class jline.ConsoleReader
[groovyc] reader.setDefaultPrompt("groovy> ");
[groovyc] ^
The jline dependency is correctly resolved, but strangely the setDefaultPrompt method does not appear to be present in the jar:
$ javap -classpath target/lib/compile/jline-0.9.94.jar jline.ConsoleReader | grep setDefaultPrompt
$
(Other methods appear missing from the javap output as well, but setDefaultPrompt is the one breaking my build.)
I've tried wiping out jline from my local maven repository and trying again, to no avail. I've also checked the jline jarfile from Maven Central as well as a mirror with the same results.
Oddly, I can copy the jar file to a different machine (a Sun) and perform the exact same steps and I see the setDefaultPrompt method in the jar file as expected. Others have successfully performed the same steps on a Mac as well.
What could be happening on my machine which would prevent the Java toolchain from seeing methods contained in the jar file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的机器上也有同样的问题(编译 JRuby,而不是 Groovy)。
我的问题的解决方案是我在 /Library/Java/Extensions/jline-0_9_5.jar 中发现了一个古老的 jline jar,所以我将其删除并用更现代的版本替换它。
I had the same problem on my machine (compiling JRuby, rather than Groovy).
The solution to my problem was that I discovered an ancient jline jar at /Library/Java/Extensions/jline-0_9_5.jar, so I nuked it and replaced it with a more modern version.
您必须拥有不同版本的 JAR 文件。
You must have different versions of the JAR file.
在使用 java 1.5.0_13 的 Mac 10.5.8 上无法重现
如果您提取
jline-0.9.94.jar
并读取其META-INF/MANIFEST.MF
那么您可以发现这个jar是由java 1.4.2_16编译的:JRE向后兼容得很好,但是你的1.6.0_22和1.4.2_16之间的距离很大。
所以,我想你从源代码重新编译jline。
Not reproducible on my Mac 10.5.8 with java 1.5.0_13
If you extract
jline-0.9.94.jar
and read itsMETA-INF/MANIFEST.MF
then you may find that this jar was compiled by java 1.4.2_16:JRE is well backward compatible, but a distance between your 1.6.0_22 and 1.4.2_16 is very big.
So, I suppose you to recompile jline from source code.