Borrar filtros
Borrar filtros

Calling Java from Matlab

6 visualizaciones (últimos 30 días)
Kyle
Kyle el 17 de Oct. de 2012
Editada: per isakson el 14 de Mzo. de 2018
I've seen there are a number of descriptions about this on the web, but I seem to be running into trouble. I have a simple Java function that I have compiled successfully in Java
// Java Code
//*------------------------------------
package testfunction;
public class TestFunction
{
public static void main(String[] args) {
System.out.println("Hello, World");
}
}
//*------------------------------------
and I am attempting to load and call from Matlab
%%Matlab Code
% ---------------------------------------
javaclasspath({
'C:\Users\username\Desktop\JavaFunctions\TestFunction', ...
'C:\Users\username\Desktop\JavaFunctions\TestFunction\dist\TestFunction.jar'...
});
import testfunction.*
import testfunction.TestFunction
% ----------------------------------------
I can't even get test function to import correctly, I'm sure I'm missing something I just don't know what. Any assistance is welcome

Respuesta aceptada

Malcolm Lidierth
Malcolm Lidierth el 20 de Oct. de 2012
You have an instance of the Java VM running already with MATLAB so you do not need a main entry point. For hello world, just use a standard static method.
package a.b;
public class TestFunction {
private TestFunction(){
}
public static void HelloWorld() {
System.out.println("Hello, World");
}
}
In MATLAB
javaaddpath...
a.b.TestFunction.HelloWorld()
To create an instance method:
package a.b;
public class TestFunction {
public TestFunction(){
}
public void HelloWorld() {
System.out.println("Hello, World");
}
}
In MATLAB
x=a.b.TestFunction();
x.HelloWorld();
  1 comentario
Kyle
Kyle el 16 de Mayo de 2013
thank you for the assistance

Iniciar sesión para comentar.

Más respuestas (1)

Sachin Ganjare
Sachin Ganjare el 18 de Oct. de 2012
  1 comentario
Kyle
Kyle el 16 de Mayo de 2013
thanks for the links they helped with an additional issue

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by