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

1
  • 1
    Have a look at this answer. 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. Commented Jan 7, 2015 at 7:08

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

The java version is the issue. I use Java 8 to compiled the source code while the matlab uses Java 6

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.