Requirements to use functions from my own jar file

4 次查看(过去 30 天)
Hi, I am trying to use my java functions in Matlab. I know how to add jar file to Matlab path. I know that I am supoused to put constructor in my java class (I don't know why, but MatLab cannot find it without constructor). And even with the constructor I am not able to call my functions if they are in some packege. It works only when placed in default package, when the class file is in root of the jar file.
clear all, close all, clc
javaaddpath(fullfile(pwd,'myTestFunction.jar'))
%Check if it is added
javaclasspath
%%a. Call Public Static Functions of the Class
% Public static functions of a Java class can be called without having to create an instance of that class.
TestFunction.main('') % Call public static functions of the HelloWorld class
%%b. Create an Instance of the Class
% To create an instance of my class, issue the following command at the MATLAB command prompt:
instance = TestFunction % Create an instance of the class through the constructor
%%c. Call method of the Class
instance.Add(5)
instance.Add(5)
  • Am I making something wrong with my java code or jar export?
  • Is there a way to use classes if they are in package(s)?

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Call Java from MATLAB 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by