4

I'm using an external jar (developped by me) into my matlab projet (developped by me) with javaaddpath command.

I have updated my programming environnement from Matlab r2011a to r2012b, jdk from 1.6.0_29 to 1.7.0_09 and windows from XP to Seven.

Firstly I have not recompiled my jar file, and my whole project is still working (running without bug).

But now, I'm trying to recompile my jar file. I had some problem with that, but it solved (see: javac @<opiton_file> and encoding). But now that my jar tool is rebuilt, I can't use it into matlab... Matlab display the error:

Undefined variable "optimizer" or function "optimizer.Gui".

where optimizer is a package (ie a directory inside the jar file, directory which contain a Gui class).

To summarize, I'm using the code (the last line must popup a JFrame) :

javaaddpath('the full path of my jar file.jar');
optimizer.Gui;

Without updating the compiled version of the jar file, it's working. With the new version (same source code), matlab output the error.

I have a Main class (containing a main function) at the root of the jar file and a manitifest specifying this Main class as the main class. This Main class make some test, to ensure all the functionnalities into the jar file is working. So I can run java -jar my_jar_file.jar and see that all test are OK (one of the test displayed my optimizer.Gui).

Is there an incompatibility of the javac version and matlab? Of is it because I had some trouble with file encoding?...

Community
  • 1
  • 1
Alexxx
  • 766
  • 1
  • 11
  • 19

2 Answers2

2

Ok, I've re-installed the JDK 1.6.0_37 (the last avaible 1.6 version). I've used my build tool (create_jar.bat), by just forcing the path to this old jdk. And it's working like a charm under Matlab r2012b!

--> Matlab r2012b is not compatible with jar file built with the jdk 1.7.

(Thank you Matworks to not prevent from this).

Alexxx
  • 766
  • 1
  • 11
  • 19
  • You can use `setenv()` to set the JAVA_HOME variable to the proper version of `Java` on the fly (assuming it has been already installed). For example: `setenv('JAVA_HOME', 'C:\Progra~1\Java\jdk1.7.0_11')` for `Matlab` r2014b. – imriss Feb 25 '15 at 17:58
1

That hasen't anything to do with MATLAB. Its a general JAVA design limitation. You cant use classes compiled for JRE7 in JRE6.

Since MATLAB used JRE6 you can't use JAVA 7 classes due the limitation from the JAVA side.

  • Ok, but it's not written into the Matlab documentation (javaaddpath) that we must used the jdk 1.6 to compile our jar. They can write a disclaimer... Moreover javaaddpath is working, because the jar file is listed into the dynamic part of javaclasspath. They can add a check to the java version of the jar file when loading them.It's a commercial product, which is really expensive! They provide a documented / supported function to load and use external jar, so even if this bug is inherent to Java, it has something to do with Matlab! ;) – Alexxx Jan 09 '13 at 14:04