Mac OS X 上没有 Java 源代码

发布于 2024-12-03 22:46:33 字数 2083 浏览 6 评论 0 原文

我认为我的 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主目录中。

I think my JDK is broken. I am on OS X 10.6.8.

I want to look in the sources when debugging in Eclipse, etc, but Eclipse can't find the sources, so I looked up the installed JREs and found this path with the title JVM 1.6.0 (MacOS X Default)

/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home

In Terminal I went to the directory /System/Library/Frameworks/JavaVM.framework/Versions and executed 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

So Eclipse already has the proper JDK linked.
Another test:

$ 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

So it all looks fine, but there is no rt.jar or src.jar Here is a screenshot:

A screenshot showing the jars in the current JDK.

So I try to reinstall it. I go to Apple's website and download this package: Java for Mac OS X 10.6 Update 5 Developer Package, file: javadeveloper_for_mac_os_x_10.6__10m3425.dmg.
The installation finished successfully, but it doesn't change anything.

I show the last modified files on my computer, these are only some java tools, located in usr/share/java/Tools

  • Java VisualVM
  • Jar Bundler
  • Applet Launcher

There still is no rt.jar or src.jar in the java home directory.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甜妞爱困 2024-12-10 22:46:33

注意:这个答案是旧的,并且适用于 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

回眸一笑 2024-12-10 22:46:33

来自: http://lookfirst.com /2011/03/fix-missing-source-for-java-mac-os-x.html(根据需要调整版本号和路径)

  1. 转到http://connect.apple.com 并下载 Java for Mac OS X 10.6 Update 4 Developer Package
  2. 安装它。
  3. 打开 Terminal.app 窗口
  4. cd /System/Library/Frameworks/JavaVM.framework/Home
  5. sudo ln -s /Library/Java/JavaVirtualMachines/1.6.0_24-b07-334.jdk/Contents/Home/src.jar 。
  6. sudo ln -s /Library/Java/JavaVirtualMachines/1.6.0_24-b07-334.jdk/Contents/Home/docs.jar 。

From: http://lookfirst.com/2011/03/fix-missing-source-for-java-mac-os-x.html (adapt version #s and paths as needed)

  1. Go to http://connect.apple.com and download Java for Mac OS X 10.6 Update 4 Developer Package
  2. Install it.
  3. Open a Terminal.app window
  4. cd /System/Library/Frameworks/JavaVM.framework/Home
  5. sudo ln -s /Library/Java/JavaVirtualMachines/1.6.0_24-b07-334.jdk/Contents/Home/src.jar .
  6. sudo ln -s /Library/Java/JavaVirtualMachines/1.6.0_24-b07-334.jdk/Contents/Home/docs.jar .
蓝咒 2024-12-10 22:46:33

致所有那些花了几个小时到处搜索源代码但最终一无所获的人们。

对于要附加的 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文