Ivan
Ivan

Reputation: 7746

HelloWorld.java from matlab

Trying to call this function from matlab

package a.b;

public class TestFunction { 
public TestFunction(){
}
public static void HelloWorld() {
 System.out.println("Hello, World");
 }
} 

I compiled it and got a class file:

[idf@localhost b]$ ls
TestFunction.class  TestFunction.java
[idf@localhost b]$ pwd
/home/idf/Documents/java/a/b
[idf@localhost b]$ 

I added the path to the parent directory in matlab

javaaddpath('/home/idf/Documents/java/')

If I try to import the package or call it I get errors:

>> import a.b
Error using import
Import argument 'a.b' cannot be found or cannot be imported.

How do I call the java function TestFunction.HelloWorld from matlab?

Upvotes: 0

Views: 90

Answers (1)

Stephen C
Stephen C

Reputation: 719109

>> import a.b
Error using import
Import argument 'a.b' cannot be found or cannot be imported.

This tells Matlab to import a class called b from a package called a. To import all classes in the package a.b, do this:

>> import a.b.*

To import just TestFunction

>> import a.b.TestFunction

Reference: matlab documentation for import

Upvotes: 1

Related Questions