Why can I not import my Java classes that are declared as part of a package?

3 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 27 Jun. 2009
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');

Weitere Antworten (0)

Kategorien

Mehr zu Call Java from MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2009a

Community Treasure Hunt

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

Start Hunting!

Translated by