Mixed class loading in Spring Boot causes java.lang.NoSuchMethodError

62 Views Asked by At

I have a fairly complex spring boot application with uses a bunch of 3:rd part packages, among others the org.ejml math library. This library is used by several jar files in my application, for instance by the stanford-nlp and my own tsne library and my own LDA library. The lda and tsne are built as fat JARs and include the entire ejml while the stanford-nlp packages it some other way. There are different versions of the EJML library, but all use a version of EJML library that implements a method called subtract(DMatrixD1,DMatrixD1,DMatrixD1) but when I run my Spring Boot application it throws an java.lang.NoSuchMethodError: 'void org.ejml.dense.row.CommonOps_DDRM.subtract(org.ejml.data.DMatrixD1, org.ejml.data.DMatrixD1, org.ejml.data.DMatrixD1)' how can this be?

I used the -verbose:class to try to figure out where the offending code was loaded, which it seems are from the LDA library (which uses ejml-0.41), but my code path starts in the tsne library (which uses the ejml-0.39), is this the cause of the problem? Can the 0.41 version of ejml not use a DMatrix1D object from the 0.39 version although they both implement the subtract method? If so how do I fix the problem, so that (spring/java) uses the correct (0.39 version I guess) for the subtract operation...

1

There are 1 best solutions below

4
scatolone On

I think you have 2 options here. You could exclude the ejml-0.41 dependency from the LDA library, so it will use ejml-0.39, but this option it is not grantee to work. The second option, which is the correct one in my opinion, is to use a version of the LDA that uses ejml-0.39 or a version of the tsne library that uses ejml-0.41 in a way that there aren't different versions of the same dependency.