Matlab在jar包中看不到我的一些java类(不是全部)
我有一个问题让我发疯。Matlab只看到我的一些类嵌入在JAR文件中
如果我编译包外部的类,并使用javaaddpath将路径添加到Matlab中的类,我不会遇到任何问题
当我在包中编译类,然后尝试在Matlab下访问它们时,我遇到了问题。下面是一些 Matlab 代码
>>javaaddpath('/Users/me/Documents/workspace/EKGTest.jar');
>>clear java
>>import com.neurosky.thinkgear.*
>>methods('EkgSense')
Methods for class com.neurosky.thinkgear.EkgSense:
EkgSense getClass notify reset
addTemplate getClassificationResults notifyAll toString
equals hashCode processData wait
>>methods('EkgEpoch')
No methods for class EkgEpoch or no class EkgEpoch
现在,我查看包中,所有类都是公共的。这是以下结果:jar -tf
osx:/Users/me/Documents/workspace> jar tf EKGTest.jar
META-INF/MANIFEST.MF
META-INF/REFACTORINGS.XML
com/
com/neurosky/
com/neurosky/thinkgear/
com/neurosky/thinkgear/EkgEpoch.class
com/neurosky/thinkgear/EkgEpoch.java
com/neurosky/thinkgear/EkgParameters.class
com/neurosky/thinkgear/EkgParameters.java
com/neurosky/thinkgear/EkgTemplate.class
com/neurosky/thinkgear/EkgTemplate.java
com/neurosky/thinkgear/Matlab.class
com/neurosky/thinkgear/Matlab.java
com/neurosky/thinkgear/EkgSense.class
com/neurosky/thinkgear/EkgSense.java
com/neurosky/thinkgear/DistanceArray.class
com/neurosky/thinkgear/DistanceArray.java
及以下javap --classpath
osx:/Users/me/Documents/workspace> javap -classpath /Users/me/Documents/workspace/EKGTest.jar com.neurosky.thinkgear.EkgEpoch
Compiled from "EkgEpoch.java"
public class com.neurosky.thinkgear.EkgEpoch extends java.lang.Object implements java.lang.Cloneable{
public int numberOfSamples;
public float[] data;
public com.neurosky.thinkgear.EkgEpoch(int);
public com.neurosky.thinkgear.EkgEpoch(int, float[]);
public com.neurosky.thinkgear.EkgEpoch(float[]);
public com.neurosky.thinkgear.EkgEpoch(com.neurosky.thinkgear.EkgEpoch);
public com.neurosky.thinkgear.EkgEpoch(org.json.JSONArray);
public org.json.JSONArray toJSONArray();
public static float[] convolve(float[], float[]);
public float getLineNoiseAmplitude();
public com.neurosky.thinkgear.EkgEpoch subtract(com.neurosky.thinkgear.EkgEpoch);
public com.neurosky.thinkgear.EkgEpoch subEpoch(int, int);
public com.neurosky.thinkgear.EkgEpoch square();
public com.neurosky.thinkgear.EkgEpoch subtract(float);
public com.neurosky.thinkgear.EkgEpoch diff();
public boolean exceedValue(float, int, int);
public com.neurosky.thinkgear.EkgEpoch smooth(int);
public float mean();
public float sum();
public float max();
public float median();
public com.neurosky.thinkgear.EkgEpoch clone();
public com.neurosky.thinkgear.EkgEpoch sort();
public int[] sortIndices(com.neurosky.thinkgear.EkgEpoch);
public float std();
public int find_heart_beats(int[], float);
public com.neurosky.thinkgear.EkgEpoch detrend();
public java.lang.Object clone() throws java.lang.CloneNotSupportedException;
}
osx:/Users/me/Documents/workspace> javap -classpath /Users/me/Documents/workspace/EKGTest.jar com.neurosky.thinkgear.EkgSense
Compiled from "EkgSense.java"
public class com.neurosky.thinkgear.EkgSense extends java.lang.Object{
public com.neurosky.thinkgear.EkgParameters params;
public com.neurosky.thinkgear.EkgTemplate[] templates;
public com.neurosky.thinkgear.EkgTemplate currentData;
public int lastTemplateInd;
public float lastEpochValue;
public com.neurosky.thinkgear.EkgSense(com.neurosky.thinkgear.EkgParameters);
public void reset();
public void addTemplate(java.lang.String, float[][]);
public void addTemplate(com.neurosky.thinkgear.EkgTemplate);
public java.lang.String getClassificationResults();
public boolean processData(float[]);
}
我在OSX上运行Matlab。我尝试使用Matlab 7.7.0.471(R2008b)和7.11.0.584(R2010b)并遇到了同样的问题。两个Matlab都使用本机OSX Java(Java 1.6.0_26-b03-384-10M3425与Apple Inc. Java HotSpot(TM)64位服务器VM混合模式),这应该与Eclipse中的相同(我已经检查过,Eclipse使用1.6编译)。
请记住,当我删除java文件顶部的package语句和一些导入(当然在所有类中)并且当我简单地将路径添加到.class文件(不在JAR文件中访问它们)时,我可以看到缺少的类没有问题。
任何帮助将不胜感激。谢谢
杰森