Why can I not import my Java classes that are declared as part of a package?
2 次查看(过去 30 天)
显示 更早的评论
If I have a class named "test.class" that is declared as part of package "pack", I get an undefined function error when I try to import the file.
采纳的回答
MathWorks Support Team
2009-6-27
The following code produces an "undefined function or variable 'test'" error:
javaaddpath('<root_directory>\pack');
import test.*
methodsview(test)
The source of the error is that a Java package is similar to directory. Although the directory that contains the class file has been added to the Java path, the class is still expected to be contained in a subdirectory "pack". You can fix this problem using the following code:
javaaddpath('<root_directory>');
import pack.test.*
methodsview(test)
If 'pack' is a JAR archive (.jar file), it may also be added to the Java class path as follows:
javaaddpath('<root_directory>\pack.jar');
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call Java from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!