是否需要一个特别的OpenJDK版本来支持新的苹果硅芯片?

我看到目前有macOS/OS X的JDK下载,但这些似乎只适用于x86处理器。对吗?如果是这样,我可以在哪里下载用于M1的OpenJDK版本?


当前回答

以下是安装Oracle JDK 8并从Rosetta - https://www.oracle.com/in/java/technologies/javase/javase-jdk8-downloads.html运行它的步骤

下载macOS x64版本 在尝试安装该包时,如果Rosetta已经不存在,您将收到安装它的提示 其余的安装步骤与任何其他包相同。

您可以通过打开终端并输入以下命令来验证它是否工作:

java -version

其他回答

我尝试过Azul JDK 8。

我只是想说,虽然Azul JDK在Apple M1上原生运行,而且速度非常快,但仍然存在一些问题。特别是当一些Java代码需要调用c++代码时。

例如,我是一名大数据开发人员。我开始使用Azul JDK进行开发工作流程。但是我注意到切换后某些测试开始失败。例如,当测试写入Parquet/Avro文件时,它会失败。我认为这是因为有一些用c++为Parquet/Avro编写的原生东西,而不是为M1编译的。

由于这个特殊的原因,我被迫使用速度较慢的非m1 JDK。没有什么问题。

这里有一个我用Azul得到的错误的例子,我没有得到非m1 jdk:

- convert Base64 JSON back to rpo Avro *** FAILED ***
  org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 10.0 failed 1 times, most recent failure: Lost task 0.0 in stage 10.0 (TID 14, localhost, executor driver): org.xerial.snappy.SnappyError: [FAILED_TO_LOAD_NATIVE_LIBRARY] no native library is found for os.name=Mac and os.arch=aarch64
        at org.xerial.snappy.SnappyLoader.findNativeLibrary(SnappyLoader.java:331)
        at org.xerial.snappy.SnappyLoader.loadNativeLibrary(SnappyLoader.java:171)
        at org.xerial.snappy.SnappyLoader.load(SnappyLoader.java:152)
        at org.xerial.snappy.Snappy.<clinit>(Snappy.java:47)
        at org.apache.avro.file.SnappyCodec.compress(SnappyCodec.java:43)
        at org.apache.avro.file.DataFileStream$DataBlock.compressUsing(DataFileStream.java:358)
        at org.apache.avro.file.DataFileWriter.writeBlock(DataFileWriter.java:382)
        at org.apache.avro.file.DataFileWriter.sync(DataFileWriter.java:401)
        at org.apache.avro.file.DataFileWriter.flush(DataFileWriter.java:410)
        at org.apache.avro.file.DataFileWriter.close(DataFileWriter.java:433)
        at org.apache.avro.mapred.AvroOutputFormat$1.close(AvroOutputFormat.java:170)
        at org.apache.spark.internal.io.SparkHadoopWriter.close(SparkHadoopWriter.scala:101)
        at org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsHadoopDataset$1$$anonfun$12$$anonfun$apply$5.apply$mcV$sp(PairRDDFunctions.scala:1145)
        at org.apache.spark.util.Utils$.tryWithSafeFinallyAndFailureCallbacks(Utils.scala:1393)
        at org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsHadoopDataset$1$$anonfun$12.apply(PairRDDFunctions.scala:1145)
        at org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsHadoopDataset$1$$anonfun$12.apply(PairRDDFunctions.scala:1125)
        at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:87)
        at org.apache.spark.scheduler.Task.run(Task.scala:108)
        at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:335)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

Driver stacktrace:
  at org.apache.spark.scheduler.DAGScheduler.org$apache$spark$scheduler$DAGScheduler$$failJobAndIndependentStages(DAGScheduler.scala:1499)
  at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1487)
  at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1486)
  at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
  at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
  at org.apache.spark.scheduler.DAGScheduler.abortStage(DAGScheduler.scala:1486)
  at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:814)
  at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:814)
  at scala.Option.foreach(Option.scala:257)
  at org.apache.spark.scheduler.DAGScheduler.handleTaskSetFailed(DAGScheduler.scala:814)
  ...
  Cause: org.xerial.snappy.SnappyError: [FAILED_TO_LOAD_NATIVE_LIBRARY] no native library is found for os.name=Mac and os.arch=aarch64
  at org.xerial.snappy.SnappyLoader.findNativeLibrary(SnappyLoader.java:331)
  at org.xerial.snappy.SnappyLoader.loadNativeLibrary(SnappyLoader.java:171)
  at org.xerial.snappy.SnappyLoader.load(SnappyLoader.java:152)
  at org.xerial.snappy.Snappy.<clinit>(Snappy.java:47)
  at org.apache.avro.file.SnappyCodec.compress(SnappyCodec.java:43)
  at org.apache.avro.file.DataFileStream$DataBlock.compressUsing(DataFileStream.java:358)
  at org.apache.avro.file.DataFileWriter.writeBlock(DataFileWriter.java:382)
  at org.apache.avro.file.DataFileWriter.sync(DataFileWriter.java:401)
  at org.apache.avro.file.DataFileWriter.flush(DataFileWriter.java:410)
  at org.apache.avro.file.DataFileWriter.close(DataFileWriter.java:433)

正如你所看到的,它说:Cause: org.xerial.snappy.SnappyError: [FAILED_TO_LOAD_NATIVE_LIBRARY] no native library is found for os.name=Mac and os.arch=aarch64

我谷歌了一下这个问题,他们说原生库是为Spark的后续版本编译的,不幸的是。

这让我非常沮丧,我现在想要一台Windows笔记本电脑,哈哈。在M1芯片上运行Intel JDK有时会很慢,我不希望这样。

小心!

Update: They released new versions of their libraries with support for M1, I updated them in the projects and everything works, thank God. Sometimes these "native code errors" manifest themselves with different exceptions and this is additional P.I.T.A. that I have to deal with while my colleagues on windows laptops don't need to deal with it. The errors can be a bit unclear sometimes, but if you see something about native code in the error log, or words like "jna" or "jni", then it's an M1 chip problem.

请到Azul网站下载。dmg文件:

https://www.azul.com/downloads/zulu-community/?os=macos&architecture=arm-64-bit&package=jdk

它将被放置在一个库中,一旦IntelliJ IDEA识别出它,就应该可以运行了。

Azul在其网站的下载部分提供macOS ARM版本的OpenJDK。虽然我还没有尝试过,但Azul一直是JDK的长期开发人员。

一旦你解包了Azul JDK,你必须在它里面翻找,直到你找到zulu-11。jdk目录(假设您已经下载了jdk 11),然后将其复制到/Library/Java/JavaVirtualMachines。

我成功地使用Azul OpenJDK和NetBeans在新的Apple M1芯片上开发Java应用程序。

配置:

zulu16.0.65-ea-jdk16.0.0-ea.24-macos_aarch64 NetBeans 12.1和Maven。

您可以使用sdkman安装Java JDK(参见sdkman install):

vim .sdkman/etc/config

设置sdkman_rosetta2_compatible=false(参见sdkman config)

之后,您将看到一个与M1 jdk兼容的列表:

sdk list java

================================================================================
Available Java Versions
================================================================================
 Vendor        | Use | Version      | Dist    | Status     | Identifier
--------------------------------------------------------------------------------
 Azul Zulu     |     | 16.0.1       | zulu    |            | 16.0.1-zulu
               |     | 11.0.11      | zulu    |            | 11.0.11-zulu
               |     | 8.0.292      | zulu    |            | 8.0.292-zulu
 BellSoft      |     | 16.0.1       | librca  |            | 16.0.1-librca
               |     | 11.0.11      | librca  |            | 11.0.11-librca
               |     | 8.0.292      | librca  |            | 8.0.292-librca
 Java.net      |     | 18.ea.3      | open    |            | 18.ea.3-open
               |     | 18.ea.2      | open    |            | 18.ea.2-open
               |     | 18.ea.1      | open    |            | 18.ea.1-open
               |     | 17.ea.28     | open    |            | 17.ea.28-open
               |     | 17.ea.27     | open    |            | 17.ea.27-open
               |     | 17.ea.26     | open    |            | 17.ea.26-open
               |     | 17.ea.25     | open    |            | 17.ea.25-open
================================================================================

选择一个并使用命令sdk install java IDENTIFIER安装它,即:

SDK安装Java 8.0.292-zulu