Matlab在jar包中看不到我的一些java类(不是全部) [英] Matlab cannot see some of my java classes (not all) in jar package
问题描述
我有一个让我疯狂的问题。
Matlab看到我的一些类只嵌入在JAR文件中
I have a problem that is driving me nuts. Matlab sees only some of my classes embeded in a JAR file
如果我在一个包之外编译类并在Matlab中添加类的路径javaaddpath,我没有遇到任何问题
If I compile the classes outside of a package and add the path to the class in Matlab using javaaddpath, I do not encounter any problem
当我在一个包中编译类然后尝试在Matlab下访问它时,我遇到了问题。下面是一些Matlab代码
When I compile the class in a package and then try to access them under Matlab, I have problems. Below some Matlab code
>>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
Now, I look in the package, all of the classes are public. This is a result of 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)。
I am running Matlab on OSX. I have tried with Matlab 7.7.0.471 (R2008b) and 7.11.0.584 (R2010b) and got the same problem. Both Matlab are using the native OSX Java (Java 1.6.0_26-b03-384-10M3425 with Apple Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode) which should be the same as the one in Eclipse (I have checked and Eclipse compiles with 1.6).
请记住,当我删除包语句时,我可以看到缺少的类没有问题,并且在java文件的顶部有一些导入(在当然所有的类)当我只是添加.class文件的路径(不在JAR文件中访问它们)。
Remember that I can see the missing class no problem when I remove the package statement and some imports at the top of the java files (in all the classes of course) and when I simply add the path to the .class files (not access them in a JAR file).
任何帮助将不胜感激。
谢谢,
Any help would be greatly appreciated. Thanks,
Jason
推荐答案
我终于找到了上面看不到的问题。问题(没有在任何地方记录)是我的一些类使用我没有导入到Matlab的外部包。我没有计划使用与这些软件包相关的任何功能。
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.
尽管如此,Matlab错误消息表明它找不到类令人费解。由于某些包未被引用而导致无法使用该类的错误消息将非常有用。
Nevertheless, 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.
如果您的包使用外部包,请务必进口所有JAR MATLAB下的文件或某些类不会是美国
IF YOUR PACKAGE USES EXTERNAL PACKAGES, MAKE SURE TO IMPORT ALL THE JAR FILE UNDER MATLAB OR SOME CLASSES WILL NOT BE US
我发现另一个有用的提示是,如果输入一个包,那么Matlab函数import将不会返回错误不存在*import java.doesnotexist。*工作正常。但是,import java.doesnotexist.aclass将不起作用。
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 with * "import java.doesnotexist.*" works fine. However, "import java.doesnotexist.aclass" will not work.
Jason
这篇关于Matlab在jar包中看不到我的一些java类(不是全部)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!