2

I'm trying to import a custom fat jar that has a dependency on guava-19.0 or higher. The matlab version I'm using already has a guava jar in it's classpath, but it's version 15.0. I've tried removing the jar from matlab's classpath.txt file, but matlab won't start if I do this. I've also tried creating a javaclasspath.txt file in my working directory with the lines:

<before>
path/to/myjar.jar

But that doesn't let matlab start either. Adding my jar directly to classpath.txt so it's in the static path instead of the dynamic also gives me an error when starting matlab. I'm using matlab 2016.

CoderCole
  • 55
  • 1
  • 5
  • What error do you get when you try to load Matlab with the newer guava version? It may be benign.. Either way, it is not possible to have Matlab use older version of guava and your code to use newer, unless you re-build guava itself with a different namespace (which is a massive pain) as well as the jar you're trying to load. – nirvana-msu Jan 12 '17 at 17:40
  • 1
    The error is "Internal Error: Failure occurs during desktop startup. Details: Failure Loading desktop class". Matlab won't open at all with this error. – CoderCole Jan 12 '17 at 17:44

1 Answers1

1

There's a way, but you might not like it. The problem is that by design of java class loading system, you cannot possibly use two classes with the same name and package (unless you go as far as implementing your own classloader). And as you said, Matlab itself is not compatible with the newer guava version. So the only way is to re-build google/guava with a different package name, i.e. literally change all the package names and respective imports to something unique, e.g. change com.google.* to com.google_19_0.*, and build a jar. You will then need to amend the source code of the jar you're tring to load to reference classes in your new package, rather than original guava package. That clearly assumes you can modify the source code of the jar you need.

Community
  • 1
  • 1
nirvana-msu
  • 3,877
  • 2
  • 19
  • 28
  • 1
    Unfortunately, I think you are correct. I attempted to update the source code with a new package name, but I have others jars in my project that reference guava too. They would probably have to be updated too. For now I'm just going to run the jar in MATLAB instead of trying to import it. – CoderCole Jan 19 '17 at 15:58