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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4011002/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 08:20:33  来源:igfitidea点击:

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

javaeclipsemacos

提问by Albert

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 (i.e. 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? (Please no assumptions here. I really want to know that.)

MacOSX 在某处有源吗?(请不要在这里做任何假设。我真的很想知道。)

If not, where can I get them?

如果没有,我在哪里可以得到它们?

采纳答案by Sebastian Beigel

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. Everything works as expected (until now :)

这就是我将 Eclipse 中 Java 1.6 的“JRE home”指向的地方。一切都按预期工作(直到现在:)

回答by trashgod

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.jarfor Java 6 is not present.

在 Mac OS X 10.5.8 上,更新到 Java 1.6.0_22 并安装日期为 2010 年 10 月 20 日的最新开发人员更新后,src.jarJava 6 不存在。

$ 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 codefor all constructors and methods, e.g. java.awt.Point:

导航到 NetBeans 6.9.1 中的源代码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 this thread.

可以从以前的更新中提取可用的 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.jarmay be referenced:

或者,/Library/Java/Home/src.jar可以引用该文件:

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

回答by robinr

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. 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

在 Java for Mac OS X 10.6 Update 3 发布时,Apple 移植并随 Mac OS X 一起提供的 Java 运行时已被弃用。开发人员不应依赖 Apple 提供的 Java 运行时出现在 Mac OS X Java for Mac OS X 10.6 Update 3 和 10.5 Update 8 发行说明的未来版本中

回答by Duncan McGregor

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/Java/JavaVirtualMachines/ is the new standard place - there you will find the new release.
  • /Library/Java/JavaVirtualMachines is for '...developer previews, and 3rd party JVMs'
  • /System/Library/Frameworks/JavaVM.framework/ 是旧地方。
  • /System/Library/Java/JavaVirtualMachines/ 是新的标准位置 - 您会在那里找到新版本。
  • /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). But if you install the 'Java Developer package' from Apple, you will get

默认安装的 JDK 现在没有 src.jar(虽然它是 JDK,所以有 javac 等)。但是如果你从 Apple安装“Java Developer package” ,你会得到

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

/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

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

回答by Duncan McGregor

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; 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". 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.

作为 Mac (10.6.6) 的新手,这是我为 MyEclipse 所做的,它也适用于 Eclipse;我没有在断开连接的模式下测试过这个。当尝试为 MyEclipse 8.5 添加另一个 JRE 时,它需要一个“MacOS X VM”,并且不支持“标准 VM”。我尝试修改 eclipse.ini 和 myeclipse.ini 文件,还尝试使用特定的 JAVA_HOME 集从命令行启动 MyEclipse,但无济于事。

1) download and install the correct 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. As of today, the downloaded file name was javadeveloper_10.6_10m3261.dmg.

1) 下载并安装正确的 Java Developer Package。转到系统偏好设置 -> 软件更新 -> 已安装的软件。您可能有多个版本的给定安装,就我而言,我有“Java for Mac OS X 10.6 Update 2”和“Java for Mac OS X 10.6 Update 3”——所以一定要按名称排序,或验证一些另一种方式。截至今天,下载的文件名为 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. I have slightly modified security permissions, so you may or may not need to use sudo to create the symlinks.

2) 在终端窗口中,我添加了一些来自 OS VM 的符号链接,这些符号链接指向标准 VM 中的 jar。我稍微修改了安全权限,因此您可能需要也可能不需要使用 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

回答by romeroabelleira

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。

回答by Brill Pappin

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...

烦到没完没了...

回答by Pipalayan Nayak

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)

  • go to Downloads for Apple developersand then search for java.

  • I have chosen "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/

    Hope this helps!

  • 如前所述,您必须注册 Apple 开发者帐户。(免费)

  • 转到Apple 开发人员的下载,然后搜索 java。

  • 我选择了“Java for OS X 2013-005 Developer Package”
  • 下载并安装软件包后,您将在 /Library/Java/JavaVirtualMachines/1.6.0_65-b14-462.jdk/Contents/Home/ 找到 src.jar

    希望这可以帮助!

回答by skong

as of today, 6/1/12, the Java Devloper Package for OSX 10.7, no longer come with src.jar under Home directory. Some google results pointing to Apple's decision in 2010 to deprecate Java support in OSX (the ported one by Apple). And Oracle start providing Mac OS X JDK since this April. So going forward, install JDK from Oracle.

截至今天,2012 年 6 月 1 日,用于 OSX 10.7 的 Java Devloper 包不再随附在 Home 目录下的 src.jar。谷歌的一些结果表明,苹果在 2010 年决定弃用 OSX 中的 Java 支持(苹果移植的那个)。Oracle 从今年 4 月开始提供 Mac OS X JDK。所以接下来,从 Oracle 安装 JDK。

回答by sven.ludwig

With Oracle Java SE 7 for Mac OS X x64 the src.zip ends up in the following location, in this case the particular version is Java SE 7u10

对于 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