Use my owe Java class in MATLAB
Show older comments
Hello everyone,
I want to use a Java class in my MATLAB code, which is called 'Myclass.java'. I have compiled it with Java8 and the output 'Myclass.class' is in the folder 'C:\Documents\MATLAB\'.
Here is my Java code.
package com.Myclass;
public class JavaMatlab {
public void Myfunction(){
//My function code
}
}
I want to use this class and its methods in MATLAB and my code is as below:
avaaddpath('C:\Documents\MATLAB\')
import com.Myclass.*;
Myclass=javaObject('com.Myclass.JavaMatlab');
But it gives an error, it tells me MATLAB cannot find class com.Myclass.JavaMatlab in Java class path.
The version -java gives 'Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode'
version -java
The Java version of my computer is 1.8.0_333-b02.
Can you help me settle this problem? Thanks.
Accepted Answer
More Answers (1)
Sourav Sukumaran
on 29 Jun 2022
0 votes
Hi
I understand that without the class being in a package the javaObject function works. Please refer to this article :
wherein a java function gets compiled into a package using library compiler.
Thanks
Categories
Find more on Call Java from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


