Deeplearning4j for Minecraft Plugins (Doesn't work due to different entry point)

@Joehot200 add this to your plugin and it will work:

  ND4JClassLoading.setNd4jClassloader(this.getClassLoader());

Full class:

public class DL4jMinecraft extends JavaPlugin  {
    @Override
    public InputStream getResource(String filename) {
        return super.getResource(filename);
    }

    @Override
    public void onEnable() {
        super.onEnable();
        System.setProperty("org.bytedeco.javacpp.logger.debug","true");
        ND4JClassLoading.setNd4jClassloader(this.getClassLoader());
        INDArray arr = Nd4j.ones(1);
        System.out.println("Created ndarray");
    }
}

Note the: this.getClassLoader() call. Similar to the thread you link I think we do use the context classloader by default which caused this issue.

Note we also have a:
Dl4jClassLoading as well.

That will be:

import org.deeplearning4j.common.config.DL4JClassLoading; 

DL4JClassLoading.setDl4jClassloader(this.getClassLoader());

1 Like