简体   繁体   English

MacOSX 上的 Java/Eclipse:src.zip 在哪里?

[英]Java/Eclipse on MacOSX: where is the src.zip?

With the latest Java update on MacOSX 10.6, Eclipse does not find the Java sources anymore.随着 MacOSX 10.6 上最新的 Java 更新,Eclipse 不再找到 Java 源代码。

I am not exactly sure (ie don't remember anymore) if I have downloaded the sources manually in the past and put them somewhere or if MacOSX provided them and Eclipse found them automatically.我不太确定(即不再记得了)是我过去手动下载了源代码并将它们放在某处,还是 MacOSX 提供了它们并且 Eclipse 自动找到了它们。

Does MacOSX have the sources somewhere? MacOSX 在某处有源吗? (Please no assumptions here. I really want to know that.) (请不要在这里做任何假设。我真的很想知道。)

If not, where can I get them?如果没有,我在哪里可以得到它们?

As I understand it, as of "Java for Mac OS X 10.6 Update 3", there are 3 places you will find Java installed on MacOS.据我了解,从“Java for Mac OS X 10.6 Update 3”开始,您可以在 3 个地方找到 Java 安装在 MacOS 上。

  • /System/Library/Frameworks/JavaVM.framework/ was the old place. /System/Library/Frameworks/JavaVM.framework/ 是旧地方。
  • /System/Library/Java/JavaVirtualMachines/ is the new standard place - there you will find the new release. /System/Library/Java/JavaVirtualMachines/ 是新的标准位置 - 您会在那里找到新版本。
  • /Library/Java/JavaVirtualMachines is for '...developer previews, and 3rd party JVMs' /Library/Java/JavaVirtualMachines 用于“...开发者预览和 3rd 方 JVM”

Note the MacOS rule of putting Apple-supplied standard components in /System/Library and local extensions into /Library请注意将 Apple 提供的标准组件放入 /System/Library 并将本地扩展放入 /Library 的 MacOS 规则

The JDK installed by default does not now have a src.jar (although it is a JDK, so has javac etc).默认安装的 JDK 现在没有 src.jar(虽然它是 JDK,所以有 javac 等)。 But if you install the 'Java Developer package' from Apple , you will get但是如果你从 Apple安装“Java Developer package”,你会得到

/Library/Java/JavaVirtualMachines/1.6.0_22-b04-307.jdk

which has src.jar under Contents/Home在 Contents/Home 下有 src.jar

So I think that the sane thing to do is install the developer package and point to it from your IDE.所以我认为明智的做法是安装开发包并从您的 IDE 指向它。


Update - for "Java for Mac OS X 10.7 Update 1", having installed the developer package the source can be found at更新 - 对于“Java for Mac OS X 10.7 Update 1”,安装开发包后,可以在以下位置找到源代码

/Library/Java/JavaVirtualMachines/1.6.0_29-b11-402.jdk/Contents/Home/src.jar

After installing the most recent Java update you'll find src.jar under安装最新的 Java 更新后,您将在下面找到 src.jar

/Library/Java/JavaVirtualMachines/1.6.0_22-b04-307.jdk/Contents/Home /Library/Java/JavaVirtualMachines/1.6.0_22-b04-307.jdk/Contents/Home

That's where I pointed "JRE home" for Java 1.6 in Eclipse to.这就是我在 Eclipse 中将 Java 1.6 的“JRE home”指向的地方。 Everything works as expected (until now :)一切都按预期工作(直到现在:)

This is my experience with src.jar !.这是我使用 src.jar 的经验!。

  • As mentioned earlier, you will have to sign up for the Apple developer account.(its free)如前所述,您必须注册 Apple 开发者帐户。(免费)

  • go to Downloads for Apple developers and then search for java.转到Apple 开发人员的下载,然后搜索 java。

  • I have chosen "Java for OS X 2013-005 Developer Package"我选择了“Java for OS X 2013-005 Developer Package”
  • Once you download and install the package, you will find src.jar at /Library/Java/JavaVirtualMachines/1.6.0_65-b14-462.jdk/Contents/Home/下载并安装软件包后,您将在 /Library/Java/JavaVirtualMachines/1.6.0_65-b14-462.jdk/Contents/Home/ 找到 src.jar

    Hope this helps!希望这有帮助!

It appears in the latest OSX 10.6.7 (java 1.6.0_24) they have cleaned up all those directories... no src.jar exists anywhere and most of the indicated directories are missing.它出现在最新的 OSX 10.6.7 (java 1.6.0_24) 中,他们已经清理了所有这些目录......任何地方都没有 src.jar 并且大多数指示的目录都丢失了。

annoying to no end...烦到没完...

as of today, 6/1/12, the Java Devloper Package for OSX 10.7, no longer come with src.jar under Home directory.截至今天,2012 年 6 月 1 日,用于 OSX 10.7 的 Java Devloper 包不再随附在 Home 目录下的 src.jar。 Some google results pointing to Apple's decision in 2010 to deprecate Java support in OSX (the ported one by Apple).谷歌的一些结果表明,苹果在 2010 年决定弃用 OSX 中的 Java 支持(苹果移植的那个)。 And Oracle start providing Mac OS X JDK since this April. Oracle 从今年 4 月开始提供 Mac OS X JDK。 So going forward, install JDK from Oracle.所以接下来,从 Oracle 安装 JDK。

对于 Mac OS X x64 的 Oracle Java SE 7,src.zip 最终位于以下位置,在这种情况下,特定版本是 Java SE 7u10

/Library/Java/JavaVirtualMachines/jdk1.7.0_10.jdk/Contents/Home/src.zip

Call me old fashioned, but:叫我老式,但是:

find /Library/Java/JavaVirtualMachines/ -name src.jar查找 /Library/Java/JavaVirtualMachines/ -name src.jar

worked for me :-)为我工作:-)

On Mac OS X 10.5.8, after updating to Java 1.6.0_22 and installing the most recent developer update dated 20-Oct-2010, src.jar for Java 6 is not present.在 Mac OS X 10.5.8 上,更新到 Java 1.6.0_22 并安装最新的开发人员更新(2010 年 10 月 20 日)后,Java 6 的src.jar不存在。

$ find /System/Library/Java /System/Library/Frameworks -name src.jar
/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home/src.jar
/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/src.jar

Navigating to source in NetBeans 6.9.1 says compiled code for all constructors and methods, eg java.awt.Point :导航到 NetBeans 6.9.1 中的源compiled code表示所有构造函数和方法的compiled code ,例如java.awt.Point

public Point() {
    //compiled code
    throw new RuntimeException("Compiled Code");
}

It may be possible to extract a usable JAR from a previous update, as suggested in thisthread .可以从以前的更新中提取可用的 JAR,如本线程中所建议的。

Addendum: On NetBeans, the default platform's location is an attribute in the file ~/.netbeans/6.9/config/Services/Platforms/org-netbeans-api-java-Platform/default_platform.xml :附录:在 NetBeans 上,默认平台的位置是文件~/.netbeans/6.9/config/Services/Platforms/org-netbeans-api-java-Platform/default_platform.xml一个属性:

<sources>
    <resource>jar:file:/Library/Java/JavaVirtualMachines/
        1.6.0_22-b04-307.jdk/Contents/Home/src.jar!/src/
    </resource>
</sources>

Alternatively, the file /Library/Java/Home/src.jar may be referenced:或者,可以引用文件/Library/Java/Home/src.jar

<sources>
    <resource>jar:file:/Library/Java/Home/src.jar!/src/</resource>
</sources>

Maybe this explains it: ?也许这可以解释它:?

As of the release of Java for Mac OS X 10.6 Update 3, the Java runtime ported by Apple and that ships with Mac OS X is deprecated.从 Java for Mac OS X 10.6 Update 3 的发布开始,Apple 移植并随 Mac OS X 一起提供的 Java 运行时已被弃用。 Developers should not rely on the Apple-supplied Java runtime being present in future versions of Mac OS X Java for Mac OS X 10.6 Update 3 and 10.5 Update 8 Release Notes开发人员不应依赖 Apple 提供的 Java 运行时出现在 Mac OS X Java for Mac OS X 10.6 Update 3 和 10.5 Update 8 发行说明的未来版本中

If you want Eclipse to always point to the current default JDK and its sources point it to:如果您希望 Eclipse 始终指向当前的默认 JDK 并且它的源指向它:

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

Eclipse will then resolve the symbolic link CurrentJDK and point it to the current JDK.然后 Eclipse 将解析符号链接 CurrentJDK 并将其指向当前 JDK。

if nothing is working just download the sources from http://jdk7src.sourceforge.net/ here and add them.如果没有任何效果,只需从http://jdk7src.sourceforge.net/下载源代码并添加它们。 worked for me.为我工作。

Thanks to folks that have previously provided answers;感谢之前提供答案的人; they've been helpful.他们很有帮助。

As a newb to Mac (10.6.6), here's what I did for MyEclipse, which should also work for Eclipse;作为 Mac (10.6.6) 的新手,这是我为 MyEclipse 所做的,它也适用于 Eclipse; I've not tested this in a disconnected mode.我没有在断开连接的模式下测试过这个。 When trying to add another JRE for MyEclipse 8.5, it required a "MacOS X VM", and would not support a "Standard VM".当尝试为 MyEclipse 8.5 添加另一个 JRE 时,它需要一个“MacOS X VM”,并且不支持“标准 VM”。 I tried modifying both the eclipse.ini and myeclipse.ini files, and also tried starting MyEclipse from the command line with a specific JAVA_HOME set with no avail.我尝试修改 eclipse.ini 和 myeclipse.ini 文件,还尝试使用特定的 JAVA_HOME 集从命令行启动 MyEclipse,但无济于事。

1) download and install the correct Java Developer Package. 1) 下载并安装正确的 Java Developer Package。 Go to System Preferences -> Software Update -> Installed Software.转到系统偏好设置 -> 软件更新 -> 已安装的软件。 You may have multiple versions of a given installation, in my case, I had both "Java for Mac OS X 10.6 Update 2" and "Java for Mac OS X 10.6 Update 3" - so be sure to sort by name, or verify some other way.您可能有多个版本的给定安装,就我而言,我有“Java for Mac OS X 10.6 Update 2”和“Java for Mac OS X 10.6 Update 3”——所以一定要按名称排序,或验证一些其他方式。 As of today, the downloaded file name was javadeveloper_10.6_10m3261.dmg.截至今天,下载的文件名为 javadeveloper_10.6_10m3261.dmg。

2) In a terminal window, I added some symlinks from the OS VM that point to jars in the Standard VM. 2) 在终端窗口中,我添加了一些来自 OS VM 的符号链接,这些符号链接指向标准 VM 中的 jar。 I have slightly modified security permissions, so you may or may not need to use sudo to create the symlinks.我稍微修改了安全权限,因此您可能需要也可能不需要使用 sudo 来创建符号链接。

cd /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
sudo ln -s /Library/Java/JavaVirtualMachines/1.6.0_22-b04-307.jdk/Contents/Home/appledocs.jar
sudo ln -s /Library/Java/JavaVirtualMachines/1.6.0_22-b04-307.jdk/Contents/Home/docs.jar
sudo ln -s /Library/Java/JavaVirtualMachines/1.6.0_22-b04-307.jdk/Contents/Home/src.jar

Just found the src.zip on my mac at /Library/Java/JavaVirtualMachine/adoptopenjdk-11.jdk/Contents/Home/lib/src.zip刚刚在我的 Mac 上的 /Library/Java/JavaVirtualMachine/adoptopenjdk-11.jdk/Contents/Home/lib/src.zip 找到了 src.zip

Adding to 'project structure - SDKs - Sourcepath' allowed me to view java source files in IntelliJ...添加到“项目结构 - SDKs - Sourcepath”允许我在 IntelliJ 中查看 java 源文件...

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

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