Use my owe Java class in MATLAB
Ältere Kommentare anzeigen
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.
Akzeptierte Antwort
Weitere Antworten (1)
Sourav Sukumaran
am 29 Jun. 2022
0 Stimmen
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
1 Kommentar
Ziyu Hua
am 30 Jun. 2022
Kategorien
Mehr zu Call Java from MATLAB finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



