简体   繁体   中英

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

You can use system() function. eg:

[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). eg:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM