Building xgboost4j on macos: java.lang.NoClassDefFoundError: Could not initialize class

I’m developing an app that uses xgboost4j on MacOS (Ventura 13.5.1) with M1 chip.
The xgboost4j version we used was 1.7.5

The app is deployed on a Linux server so we didn’t notice the problem before, but when we implemented unittests and made them run on Mac the following error arose:

	at com.mygroup.UtilsTest.toDMatrix(
Caused by: java.lang.RuntimeException: File /lib/macos/aarch64/libxgboost4j.dylib was not found inside JAR.

NOTE: The problem happens only with JDK >11.0.13, while using JDK 8 or JDK <= 11.0.13 it works.

Following #7501, I tried to rebuild the package on my M1 Mac.

I followed the guide here for the compilation, but when launching the tests it now says:

java.lang.NoClassDefFoundError: Could not initialize class

This is thrown when XGBoost.loadModel(path) is called.

NOTE: This error happens with both JDK 8 and 11

NOTE2: The following error now appears too (may be unrelated, but it doesn’t appear with maven version of xgb)

java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

First i tried building version 1.7.5, but seeing that it lead to these errors i tried with a newer version (latest master commit, version 2.1.0-SNAPSHOT), but the problem is still the same.

I also tried brew install libomp and commenting CONFIG["USE_OPENMP"] = "OFF", but still no change after that.

Can anyone help me understand what the problem is here?
I’ve seen some people saying that recompiling on MacOS worked for them, so i don’t know what I’m doing wrong here.

Hi, currently, the JVM package doesn’t have a native binary for Apple Silicon. We’d like to have a native support for Apple Silicon and currently are raising funds to do this. If you are interested, please donate at Thanks!