Determine location of a java class loaded by Matlab

前端 未结 5 1774
无人及你
无人及你 2020-12-04 00:40

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

相关标签:
5条回答
  • 2020-12-04 01:11

    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/
    
    0 讨论(0)
  • 2020-12-04 01:16

    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()
    
    0 讨论(0)
  • 2020-12-04 01:19

    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'
    
    0 讨论(0)
  • 2020-12-04 01:26

    Since 1.5 using:

    java -verbose:class 
    

    Prints where each class was loaded from.

    0 讨论(0)
  • 2020-12-04 01:29

    Assuming that an URLClassLoader is being used, you can get the file: URL of the class file like this:

    ProblemClass.class.getResource("ProblemClass.class")
    
    0 讨论(0)
提交回复
热议问题