Ahmed Yehia
Ahmed Yehia

Reputation: 1

how to run a jar file from a matlab code?

If I have a .jar file that takes two command line arguments. How can I call it from a Matlab .m file? I can call the jar file from the command line like this:

jar -jar art.jar ex.xls 0

Upvotes: 0

Views: 2732

Answers (1)

Ali
Ali

Reputation: 451

You can use system() function. e.g.:

[status result] = system('java -jar art.jar ex.xls 0');

If you need to pass variables as parameters, you have to convert them to strings and then concatenate them (with space as separator). e.g.:

jarfile = 'art.jar';
xlsfile = 'ex.xls';
n = 0;
commandtext = ['java -jar ' jarfile ' ' xlsfile ' ' num2str(n)];
system(commandtext);

Upvotes: 6

Related Questions