Cannot build in Intellij - Could not find or load main class

When building a jar in intellij withe the following pom.xml

    <properties>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>
    <kotlin.version>1.3.61</kotlin.version>
</properties>
org.deeplearning4j deeplearning4j-core 1.0.0-beta6
  <dependency>
      <groupId>org.nd4j</groupId>
      <artifactId>nd4j-api</artifactId>
      <version>1.0.0-beta6</version>
  </dependency>
  <dependency>
      <groupId>org.nd4j</groupId>
      <artifactId>nd4j-native</artifactId>
      <version>1.0.0-beta6</version>
  </dependency>
  <dependency>
      <groupId>org.deeplearning4j</groupId>
      <artifactId>deeplearning4j-ui</artifactId>
      <version>1.0.0-beta6</version>
  </dependency>
  <dependency>
      <groupId>org.freemarker</groupId>
      <artifactId>freemarker</artifactId>
      <version>2.3.29</version>
  </dependency>
  <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-math3 -->
  <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-math3</artifactId>
      <version>3.6.1</version>
  </dependency>
  <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
  <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>1.7.5</version>
  </dependency>
  <dependency>
      <groupId>org.jetbrains.kotlin</groupId>
      <artifactId>kotlin-stdlib-jdk8</artifactId>
      <version>${kotlin.version}</version>
  </dependency>
  <dependency>
      <groupId>org.jetbrains.kotlin</groupId>
      <artifactId>kotlin-test</artifactId>
      <version>${kotlin.version}</version>
      <scope>test</scope>
  </dependency>
<build>
    <plugins>
        <plugin>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-maven-plugin</artifactId>
            <version>${kotlin.version}</version>
            <executions>
                <execution>
                    <id>compile</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
                <execution>
                    <id>test-compile</id>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>test-compile</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <jvmTarget>1.8</jvmTarget>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <executions>
                <execution>
                    <id>compile</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
                <execution>
                    <id>testCompile</id>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

I have followed every single step on http://stackoverflow.com/a/42660624/104891 but when building it says “Could not find or load main class”. Why is that?

Can you run your code inside IntelliJ?
The problem present itself only when building the JAR?
Can you post all the stacktrace?

Can you share your full project? That kind of error can come from a few sources, and being able to take a look at your project structure in full context, will make debugging this a whole lot easier.

I fixed the issue by not selecting Libraries: “extract to the target JAR” but “copy to the output directory and link via manifest”. I think the issue was that all of the libraries were in the jar file and that somehow messed it up.
Is this a dl4j issue?

no, this sounds a lot like it is an issue with your project set up.

I build the project on a windows machine and ran it on a linux machine and I am getting a JRE Crash eveery time I run it is caused by nd4j.

A fatal error has been detected by the Java Runtime Environment:
SIGILL (0x4) at pc=0x00007f0e1ffb4a89, pid=11413, tid=11414
JRE version: OpenJDK Runtime Environment (11.0.6+10) (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1)
Java VM: OpenJDK 64-Bit Server VM (11.0.6+10-post-Ubuntu-1ubuntu118.04.1, mixed mode, sharing, tiered, compressed oops, serial gc, linux-amd64)
Problematic frame:
C [libnd4jcpu.so+0x57efa89] nd4j::OpTracker::getInstance()+0x29

--------------- S U M M A R Y ------------

Command Line: ./myJar.jar

Host: Intel® Xeon® CPU E5-2673 v4 @ 2.30GHz, 1 cores, 897M, Ubuntu 18.04.4 LTS
Time: Fri Mar 27 12:41:23 2020 UTC elapsed time: 1 seconds (0d 0h 0m 1s)

--------------- T H R E A D ---------------

Current thread (0x00007f0e5c014000): JavaThread “main” [_thread_in_native, id=11414, stack(0x00007f0e65305000,0x00007f0e65406000)]

This is the dump I got. Works on windows btw

Can you please share the full crash log?

Yeah I forgot this part:

--------------- T H R E A D ---------------

Current thread (0x00007f8fe8014000): JavaThread “main” [_thread_in_native, id=1700, stack(0x00007f8ff27d7000,0x00007f$

Stack: [0x00007f8ff27d7000,0x00007f8ff28d8000], sp=0x00007f8ff28d31e0, free space=1008k
Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [libnd4jcpu.so+0x57efa89] nd4j::OpTracker::getInstance()+0x29

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j java.lang.ClassLoader$NativeLibrary.load0(Ljava/lang/String;Z)Z+0 java.base@11.0.6
j java.lang.ClassLoader$NativeLibrary.load()Z+53 java.base@11.0.6
j java.lang.ClassLoader$NativeLibrary.loadLibrary(Ljava/lang/Class;Ljava/lang/String;Z)Z+216 java.base@11.0.6
j java.lang.ClassLoader.loadLibrary0(Ljava/lang/Class;Ljava/io/File;)Z+46 java.base@11.0.6
j java.lang.ClassLoader.loadLibrary(Ljava/lang/Class;Ljava/lang/String;Z)V+48 java.base@11.0.6

I meant the whole file that is created when the jvm crashes, it is usually called something like hs_XXX.log

@raver119 any idea what is going on here?

SIGILL means that you have built your project for one cpu arch, and trying to run it on a another one, so processor sees unsupported instruction. I.e. you’ve built binary for avx512 and trying to run binary on non-avx512 CPU.

p.s. the same applies to “native” builds.

Ok so I have 3 nd4j native files.

  1. nd4j-native-1.0.0-beta6.jar
  2. nd4j-native-1.0.0-beta6-windows-x86_64.jar
  3. nd4j-native-api-1.0.0-beta6.jar

So I assume I am missing the linux natives? Where do I get them from?

That’s separate story, because this fact won’t give you SIGILL. But yes, you do miss those. You can get them either by using native-platform artifact, or specify platform binaries with classifiers

So… how would I fix my issue?

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

Use this instead of nd4j-native dependency.

I did that. Deleted full maven repo and ran mvn install but the nd4j linux native is still missing.

It’s not possible, sorry. Maven must provide you with all possible artifacts, or provide meaningful error message.