4

So, I've been trying to integrate deeplearning4j(DL4j) in my Minecraft plugin and so far it's going very well. The only problem I have is shading into the jar. I successfully shaded dl4j in it but can't seem to put nd4j in it which is a library that is required for dl4j to work. Any help or advice would be greatly appreciated. I've also tried Maven-assembly and that didn't work.

Error:

[10:54:34] [Server thread/ERROR]: Error occurred while enabling AIAC  v1.0 (Is it up to date?)
java.lang.ExceptionInInitializerError
   at org.datavec.api.util.ndarray.RecordConverter.toMinibatchArray(RecordConverter.java:198) ~[?:?]
   at org.deeplearning4j.datasets.datavec.RecordReaderMultiDataSetIterator.next(RecordReaderMultiDataSetIterator.java:160) ~[?:?]
   at org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator.next(RecordReaderDataSetIterator.java:377) ~[?:?]
   at org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator.next(RecordReaderDataSetIterator.java:452) ~[?:?]
   at org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator.next(RecordReaderDataSetIterator.java:85) ~[?:?]
   at org.derock_antony.aiac.ai.Loader.<init>(Loader.java:35) ~[?:?]
   at org.derock_antony.aiac.Main.onEnable(Main.java:25) ~[?:?]
   at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
   at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-db6de12-18fbb24]
   at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-db6de12-18fbb24]
   at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot.jar:git-Spigot-db6de12-18fbb24]
   at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot.jar:git-Spigot-db6de12-18fbb24]
   at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:414) [spigot.jar:git-Spigot-db6de12-18fbb24]
   at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:378) [spigot.jar:git-Spigot-db6de12-18fbb24]
   at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:333) [spigot.jar:git-Spigot-db6de12-18fbb24]
   at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) [spigot.jar:git-Spigot-db6de12-18fbb24]
   at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [spigot.jar:git-Spigot-db6de12-18fbb24]
   at java.lang.Thread.run(Unknown Source) [?:1.8.0_201]
Caused by: java.lang.RuntimeException: org.nd4j.linalg.factory.Nd4jBackend$NoAvailableBackendException: Please ensure that you have an nd4j backend on your classpath. Please see: http://nd4j.org/getstarted.html
   at org.nd4j.linalg.factory.Nd4j.initContext(Nd4j.java:5131) ~[?:?]
   at org.nd4j.linalg.factory.Nd4j.<clinit>(Nd4j.java:226) ~[?:?]
   ... 18 more
Caused by: org.nd4j.linalg.factory.Nd4jBackend$NoAvailableBackendException: Please ensure that you have an nd4j backend on your classpath. Please see: http://nd4j.org/getstarted.html
   at org.nd4j.linalg.factory.Nd4jBackend.load(Nd4jBackend.java:218) ~[?:?]
   at org.nd4j.linalg.factory.Nd4j.initContext(Nd4j.java:5128) ~[?:?]
   at org.nd4j.linalg.factory.Nd4j.<clinit>(Nd4j.java:226) ~[?:?]
   ... 18 more

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>me.antony.aiac</groupId>
    <artifactId>aiac</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.release>12</maven.compiler.release>
    </properties>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>org.derock_antony.aiac.Main</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>8</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <artifactSet>
                                <excludes>
                                </excludes>
                            </artifactSet>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.deeplearning4j</groupId>
            <artifactId>deeplearning4j-core</artifactId>
            <version>1.0.0-beta6</version>
        </dependency>
        <dependency>
            <groupId>org.nd4j</groupId>
            <artifactId>nd4j-native-platform</artifactId>
            <version>1.0.0-beta6</version>
        </dependency>
    </dependencies>
</project>
Antony
  • 41
  • 1
  • 2

1 Answers1

1

I managed to solve this issue (I was encountering it not with a Minecraft Mod but with a Slay The Spire mod) by altering the library (nd4j) to not use the ServiceLoader feature of Java.

That error thrown by the nd4j library is only thrown when it can't find the backend (which it only tries to do using a java feature called ServiceLoaders that ostensibly don't work very well with the custom classloading being done by modded minecraft and modded slay the spire).

So just altering the library itself to hardcode the stuff that it was using ServiceLoaders to find solves the issue. I don't think this is a very good solution, but given that it is unlikely for the modded minecraft launcher or modded slay the spire launcher to fix this issue, this is one way to fix it for your own mod.

Davis
  • 1,161
  • 7
  • 8