0

I would like to use the MTJ library. But why do I get a ClassNotFoundException? How can I implement my build and code the right way?

First the error message, then the code example:

Error (gradle build; java -jar build/libs/tmp.jar):

Exception in thread "main" java.lang.NoClassDefFoundError: no/uib /cipr/matrix/DenseMatrix
    at de.piphi.Main.readMatrix(Main.java:7)
    at de.piphi.Main.main(Main.java:12)
Caused by: java.lang.ClassNotFoundException: no.uib.cipr.matrix.DenseMatrix
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

gradle.build:

apply plugin: 'java'
repositories{
    jcenter()
    mavenCentral()
}

dependencies {
    compile group: 'com.googlecode.matrix-toolkits-java', name:    'mtj', version: '1.0.2'
}

jar {
    manifest {
        attributes 'Main-Class': 'de.piphi.Main'
    }
}

src/main/java/de/piphi/Main.cpp:

package de.piphi;

import no.uib.cipr.matrix.*;

public class Main {
    static void readMatrix(){
        Matrix m = new DenseMatrix(2,2);
        System.out.println(m);
    }

    public static void main(String[] args) {
        readMatrix();
    }
}

I know Is there any example how to use Matrix Toolkit Java (MTJ)?, but the wiki page mentioned does not exist anymore.

Stefan Bollmann
  • 640
  • 4
  • 12
  • 32
  • I wonder it this is a duplicate of https://stackoverflow.com/questions/33106520/noclassdeffounderror-at-runtime-with-gradle. There http://imperceptiblethoughts.com/shadow/ is referred. I try... – Stefan Bollmann Nov 30 '17 at 19:02

1 Answers1

0

I had to add the plugin applications to build.gradle. In Main.cpp the import of import no.uib.cipr.matrix.*; must be

import no.uib.cipr.matrix.DenseMatrix;

I changed 'Matrix m = new DenseMatrix(2,2);' to

DenseMatrix m = new DenseMatrix(2,2);
Stefan Bollmann
  • 640
  • 4
  • 12
  • 32