0

I coded a simple class: test and compiled it and put it in th

'D:\Dropbox\projects\ICPR2013\code\java\union_find'. 

Code:-

public class test {
    public test() {
        System.out.printf("hello world!");
    }
}

And then I use the following code to bring the defined class to the Java class path. I also use javaclasspath to make sure that the folder including 'test' class is added to the Java class path.

javaaddpath('D:\Dropbox\projects\ICPR2013\code\java\union_find');

But when I use x = javaObjectEDT('test'); to call the 'test' class, it gives me the following error: No class test can be located on Java class path

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
Fihop
  • 3,127
  • 9
  • 42
  • 65
  • 1
    Have a look at this [answer](http://stackoverflow.com/questions/17853636/using-java-class-in-matlab/17857639#17857639). Basically check if you used the same java as matlab is using to compile your class. Also making jar files can help to bring java classes to matlab. – Marcin Jan 07 '15 at 07:08

1 Answers1

1

Assuming your class is in the file called test.java, on Ubuntu 14.04 and Matlab 2013a, you can do as follows:

  1. Compile your class file using java 6 (i.e. java version used in Matlab 2013a). Ubuntu 14.04 does not come with this java version. So you need to install it. Instructions are here.

    /usr/lib/jvm/java-6-oracle/bin/javac -d . test.java

  2. Make jar file:

    /usr/lib/jvm/java-6-oracle/bin/jar cf test.jar test.class

  3. Go to Matlab and add the jar file and run it:

    javaaddpath('/tmp/test.jar');
    test()
    hello world!

Hope this helps.

Marcin
  • 215,873
  • 14
  • 235
  • 294
  • The java version is the issue. I use Java 8 to compiled the source code while the matlab uses Java 6 – Fihop Jan 07 '15 at 18:02