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
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 个)

类别

Help CenterFile Exchange 中查找有关 Call Java from MATLAB 的更多信息

产品


版本

R2009a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by