how to invoke java program from matlab

1 次查看(过去 30 天)
Neha
Neha 2011-5-23
I have to run following code in java and invoke this class in matlab. Classpath is set as recommended.
class HelloWorld
{
public String Hello()
{
String helloWorld="Hello World!";
return helloWorld;
}
}
Now, as per guided i try to create instance obj in Matlab, with following command:
o = HelloWorld;
Here I get following err:
No constructor 'HelloWorld' with matching signature found.
The next command indicated it this:
output = o.hello;
which wouldnt work unless instance is created. Plz help how to fix this instance creation.

回答(1 个)

Neha
Neha 2011-5-23
I modified this code as follows, by including package:
package pkg1;
public class HelloWorld
{
public HelloWorld()
{
HelloWorld h = HelloWorld();
}
public String hello()
{
String helloWorld = "HelloWorld!";
return helloWorld;
}
}
Now following instructions executed:: |--> keep this file in a package called pkg1. --> Run and compile as an ordinary Java Package File, so as to create .class files. --> now your package will be stored in matlab work folder. --> so your package path is C:\Matlab\Work\pkg1 --> ------------------------------ | Now i executed following function on matlab command window:
import pkg1.*;
obj = h;
str1 = obj.hello();
Yet i have same error as mentioned above.

类别

Help CenterFile Exchange 中查找有关 Java Package Integration 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by