15

I am trying to get a Java/Maven project working on an Apple M1 with a dependency that is not yet available for the M1 chip. In my case this is nd4j but it could be any other dependency.

<dependency>
   <groupId>org.nd4j</groupId>
   <artifactId>nd4j-native</artifactId>
   <version>1.0.0-beta7</version>
</dependency>

I am using IntelliJ for this project.

I am looking for a way to specify some sort of "compatibility mode" that tells maven/IntelliJ to fetch dependencies for X86 chips and execute Java, the tests, maven, etc. with Rosetta. If that's not possible, what could be other was to solve this?

Mario Varchmin
  • 3,704
  • 4
  • 18
  • 33
Robin
  • 3,512
  • 10
  • 39
  • 73
  • 2
    Out of interest, do you have a JDK that runs natively on M1 already (or is that still using Rosetta as well)? – Thilo Mar 24 '21 at 10:27
  • I run the Azul JDK. I installed Maven via homebrew, and I think it contains an experimental OpenJDK with M1 support. My other Java projects work fine with Azul JDK as I don't have the nod4j dependency for these other projects. – Robin Mar 24 '21 at 10:33
  • 3
    Have you tried with the "normal" OpenJDK? That will still be x86, run via Rosetta, and presumably tell Maven that it's architecture is also x86. – Thilo Mar 24 '21 at 10:42
  • I just tried this after Mario's answer below. This indeed works. – Robin Mar 24 '21 at 16:16

3 Answers3

12

You can install both x86_64 based and arm64 based JDKs on your machine, and switch between these as needed. A tool like SDKMAN! can help you with that: How to install x86 and Arm JDKs on the Mac M1

If your maven and IntelliJ use the default JDK, they will automatically switch between x86_64 and Arm64 architecture, when you switch JDKs.

Mario Varchmin
  • 3,704
  • 4
  • 18
  • 33
  • Thank you very much for the answer. This does work. One minor downside is that nd4j doesn't seem to work really well with Rosetta, but I guess there is nothing we can do about that. The project builds and is runnable, so this is a huge improvement already. The tests run fine. But when using a bigger neural net, nd4j uses huge amounts of RAM and ends up throwing OOM exceptions. – Robin Mar 24 '21 at 16:21
1

Just want to update this post: we actually do properly support M1 macs now and have for a while now. Ensure you do the following:

<dependency>
  <groupId>org.nd4j</groupId>
  <artifactId>nd4j-native</artifactId>
  <version>1.0.0-M2.1</version>
</dependency>
<dependency>
  <groupId>org.nd4j</groupId>
  <artifactId>nd4j-native</artifactId>
  <version>1.0.0-M2.1</version>
  <classifier>macosx-arm64</classifier>
</dependency>
<dependency>
  <groupId>org.bytedeco</groupId>
  <artifactId>openblas</artifactId>
  <version>0.3.21-1.5.8</version>
  <classifier>macosx-arm64</classifier>
</dependency>

We do not provide support for this in the normal nd4j-native-platform. That is due to the scope of dependencies not all having mac arm versions but the math library does work out of the box.

Adam Gibson
  • 3,055
  • 1
  • 10
  • 12
0

If you use IDEA for Java on Apple, don't use IDEA M1 version, use Intel version. Then maven will use macosx-x86 jar. Just change JDK is not helpful to me.