简体   繁体   English

Mac OS X上没有Java源代码

[英]No Java source on Mac OS X

I think my JDK is broken. 我认为我的JDK坏了。 I am on OS X 10.6.8. 我在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) 我想在Eclipse等调试时查看源代码,但Eclipse无法找到源代码,因此我查找已安装的JRE并找到标题为JVM 1.6.0 (MacOS X Default)此路径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 : 在终端我去了目录/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

So Eclipse already has the proper JDK linked. 所以Eclipse已经有了正确的JDK链接。 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: 所以这一切看起来很好,但没有rt.jar或src.jar这是一个截图:

显示当前JDK中的jar的屏幕截图。

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 . 我访问Apple的网站并下载此软件包: Java for Mac OS X 10.6 Update 5 Developer Package ,文件: 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工具,位于usr/share/java/Tools

  • Java VisualVM Java VisualVM
  • Jar Bundler Jar Bundler
  • Applet Launcher Applet启动器

There still is no rt.jar or src.jar in the java home directory. java主目录中仍然没有rt.jar或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. 注意:这个答案是旧的,对于Apple Java 6.对于Oracle Java,您需要下载JDK,因为它包含src.zip。


The source is not included in the default Java download. 源未包含在默认Java下载中。 You need to additionally install the corresponding development package available from ADC. 您还需要安装ADC提供的相应开发包。

In addition, Eclipse has not yet been taught how to find the src.zip file and the dialogue cannot look inside packages. 另外,还没有教过Eclipse如何找到src.zip文件,对话框无法查看内部包。

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 在我的10.7上,上面提到的安装将src.zip放在/Library/Java/JavaVirtualMachines/1.6.0_26-b03-383.jdk/Contents/Home/src.jar中

From: http://lookfirst.com/2011/03/fix-missing-source-for-java-mac-os-x.html (adapt version #s and paths as needed) 来自: http//lookfirst.com/2011/03/fix-missing-source-for-java-mac-os-x.html (根据需要调整版本#s和路径)

  1. Go to http://connect.apple.com and download Java for Mac OS X 10.6 Update 4 Developer Package 访问http://connect.apple.com并下载适用于Mac OS X 10.6 Update 4 Developer Package的Java
  2. Install it. 安装它。
  3. Open a Terminal.app window 打开Terminal.app窗口
  4. cd /System/Library/Frameworks/JavaVM.framework/Home 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 . 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 . sudo ln -s /Library/Java/JavaVirtualMachines/1.6.0_24-b07-334.jdk/Contents/Home/docs.jar。

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 对于Eclipse要附加(1.6不完全可用): jdk1.7.0_21_src_for_mac.zip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM