简体   繁体   English

如何从Matlab代码运行jar文件?

[英]how to run a jar file from a matlab code?

If I have a .jar file that takes two command line arguments. 如果我有一个带有两个命令行参数的.jar文件。 How can I call it from a Matlab .m file? 如何从Matlab .m文件中调用它? I can call the jar file from the command line like this: 我可以从命令行像这样调用jar文件:

jar -jar art.jar ex.xls 0 jar -jar art.jar ex.xls 0

You can use system() function. 您可以使用system()函数。 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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