简体   繁体   中英

Call java class from matlab

I'm trying to call a java class from matlab(2010a) but isn't working. I tried to follow this tutorial, but didn't work.

public class Helloworld {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    // TODO code application logic here
    System.out.println( "Hello World!" );
}

1)I created this class at netbeans and compiled it using Java 1.6.0_12 (the same that is used at matlab 2010a). 2)I added the generate jar file at dynamic class path, using this command

javaaddpath('C:\Users\xx\Documents\NetBeansProjects\Helloworld\dist\Helloworld.jar');

3) I used this command, to create a object

o = HelloWorld

4)But matlab shows me this message

??? Undefined function or variable 'HelloWorld'.

Any idea about how to solve my issue?

I find my mistake, I was doing 2 mistakes.

1)I was missing the package 2)I wasn`t send the (empty)argument to the main function.

LEt me paste the full matlab code here, for someone else use in the future.

javaaddpath('C:\\Users\\xx\\Documents\\NetBeansProjects\\Helloworld\\dist\\Helloworld.jar');

%call class, inclugind the package!

% o = helloworld.Helloworld;

o = helloworld.Helloworld();

%call java method, including the argument

javaMethod('main', o,[]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM