Matlab cannot see some of my java classes (not all) in jar package

I eventually found the problem which cannot be seen above. The problem (not documented anywhere) was that some of my classes use external packages that I had not imported into Matlab. I was not planning on using any of the functionalities linked with these packages.

Nevertheless, the Matlab error message that it cannot find the class is puzzling. An error message indicating that the class cannot be used because some packages are not referenced would be most useful.

If your package uses external packages, make sure to include all of the relevant jar files in the java classpath or Matlab will not see your dependent classes.

Another tip that I found useful is that the Matlab function "import" will not return an error if you enter a package that does not exist, e.g., import java.doesnotexist.* works fine. However, import java.doesnotexist.aclass will not work.

Jason


Another reason MATLAB will not see a class is when you compile for JRE7 and are using MATLAB 2012b (probably applies to other MATLAB releases).

The symtom is the extremly lame error

The class "JavaNuServer" is undefined.
Perhaps Java is not running.

Solution:

Compile with the javac flags

-source 1.6 -target 1.6