Use my owe Java class in MATLAB
Afficher commentaires plus anciens
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.
Réponse acceptée
Plus de réponses (1)
Sourav Sukumaran
le 29 Juin 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
1 commentaire
Ziyu Hua
le 30 Juin 2022
Catégories
En savoir plus sur Call Java from MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



