When using java from Matlab, is there some way to figure out from where in matlab\'s java class path is a class being loaded? I\'m trying to diagnose a error caused by confl
From http://www.exampledepot.com/egs/java.lang/ClassOrigin.html
// Get the location of this class
Class cls = this.getClass();
ProtectionDomain pDomain = cls.getProtectionDomain();
CodeSource cSource = pDomain.getCodeSource();
URL loc = cSource.getLocation(); // file:/c:/almanac14/examples/
Per Thorbjørn Ravn Andersen, if j reference to a java object in Matlab, its location can be retrieved with the following line of matlab code:
j.getClass().getProtectionDomain().getCodeSource().getLocation().getPath()
Use the inmem function as follows:
[M,X,J] = inmem
This function returns the list of Java classes in the output argument J. (It also returns the names of all currently loaded M-files in M, and the names of all currently loaded MEX-files in X.)
Here's a sample of output from the inmem function:
[m,x,j] = inmem;
MATLAB displays:
j =
'java.util.Date'
'com.mathworks.ide.desktop.MLDesktop'
Since 1.5 using:
java -verbose:class
Prints where each class was loaded from.
Assuming that an URLClassLoader
is being used, you can get the file:
URL of the class file like this:
ProblemClass.class.getResource("ProblemClass.class")