Mac OS X 上没有 Java 源代码
我认为我的 JDK 坏了。我使用的是 OS X 10.6.8。
我想在 Eclipse 等中调试时查看源代码,但是 Eclipse 找不到源代码,因此我查找了已安装的 JRE,并找到了标题为 JVM 1.6.0 (MacOS X Default)< 的路径/code>
/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
在终端中,我进入目录 /System/Library/Frameworks/JavaVM.framework/Versions
并执行 ls -al
:
drwxr-xr-x 13 root wheel 442 8 Sep 22:46 .
drwxr-xr-x 12 root wheel 408 8 Sep 22:46 ..
lrwxr-xr-x 1 root wheel 5 8 Sep 22:45 1.3 -> 1.3.1
drwxr-xr-x 3 root wheel 102 21 Jul 2009 1.3.1
lrwxr-xr-x 1 root wheel 10 8 Sep 22:45 1.4 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 8 Sep 22:45 1.4.2 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 8 Sep 22:45 1.5 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 8 Sep 22:45 1.5.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 8 Sep 22:45 1.6 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 8 Sep 22:45 1.6.0 -> CurrentJDK
drwxr-xr-x 10 root wheel 340 8 Sep 22:46 A
lrwxr-xr-x 1 root wheel 1 8 Sep 22:45 Current -> A
lrwxr-xr-x 1 root wheel 59 8 Sep 22:45 CurrentJDK -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents
所以 Eclipse 已经链接了正确的 JDK 。 另一个测试:
$ javac -version
javac 1.6.0_26
$ which javac
/usr/bin/javac
$ ls -al /usr/bin/ | grep javac
lrwxr-xr-x 1 root wheel 75 8 Sep 22:45 javac -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/javac
所以一切看起来都很好,但是没有 rt.jar 或 src.jar 这是一个屏幕截图:
所以我尝试重新安装它。我访问 Apple 的 网站 并下载此软件包: Java for Mac OS X 10.6 Update 5 开发人员包
,文件: javadeveloper_for_mac_os_x_10.6__10m3425.dmg
。
安装成功完成,但没有改变任何东西。
我在我的计算机上显示了最后修改的文件,这些只是一些java工具,位于usr/share/java/Tools
- Java VisualVM
- Jar Bundler
- Applet Launcher
仍然没有rt.jar或src.jar在java主目录中。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
注意:这个答案是旧的,并且适用于 Apple Java 6。对于 Oracle Java,您需要下载 JDK,因为它包含 src.zip。
默认 Java 下载中不包含源代码。您需要另外安装 ADC 提供的相应开发包。
此外,Eclipse 尚未学会如何查找 src.zip 文件,并且对话无法查看包内部。
在我的 10.7 上,上述安装将 src.zip 放入 /Library/Java/JavaVirtualMachines/1.6.0_26-b03-383.jdk/Contents/Home/src.jar
NOTE: This answer is old and for Apple Java 6. For Oracle Java you need to download the JDK as it includes src.zip.
The source is not included in the default Java download. You need to additionally install the corresponding development package available from ADC.
In addition, Eclipse has not yet been taught how to find the src.zip file and the dialogue cannot look inside packages.
On my 10.7, the above mentioned installation put src.zip in /Library/Java/JavaVirtualMachines/1.6.0_26-b03-383.jdk/Contents/Home/src.jar
来自: http://lookfirst.com /2011/03/fix-missing-source-for-java-mac-os-x.html(根据需要调整版本号和路径)
From: http://lookfirst.com/2011/03/fix-missing-source-for-java-mac-os-x.html (adapt version #s and paths as needed)
致所有那些花了几个小时到处搜索源代码但最终一无所获的人们。
对于要附加的 Eclipse(对于 1.6 不完美):
jdk1.7.0_21_src_for_mac.zip
To all the guys who's been suffering from searching the source code here and there for hours but finally get nothing.
For Eclipse to attach(imperfectly available for 1.6):
jdk1.7.0_21_src_for_mac.zip