如何在Matlab中运行java .jar [英] how do I run a java .jar in Matlab

查看:371
本文介绍了如何在Matlab中运行java .jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Matlab中运行Java .jar文件。

I need to run a Java .jar file in Matlab.

让我们调用MyJar.jar文件,如果有帮助我运行Java 1.8.0_121-b13。

Let's call the file MyJar.jar, I am running Java 1.8.0_121-b13 if that helps.

我尝试了不同的解决方案,并收到了相应的错误

I have tried different solutions, and received these corresponding errors

java -jar MyJar.jar % Solution 1 Error: Attempt to execute SCRIPT java as a function: C:\Program Files\MATLAB\R2017b\toolbox\matlab\general\java.m
import MyJar        % Solution 2 Error: Import argument 'MyJar' cannot be found or cannot be imported.

我已经设置了javaclasspath:C:\ Myy \ Java @\\ Class# \\ to \ MyJar.jar(即使它没有任何帮助)

I have setup the javaclasspath: C:\My\Java\Class\Path\To\MyJar.jar (Even though it didn't help anything)

javaclasspath('C:\My\Java\Class\Path\To\MyJar.jar')

我甚至是准备编辑classpath.txt文件,(虽然,如果这是解决方案,我想通过cuz,这超出了我的理解,我不想搞砸了。)

I am even prepared to edit the classpath.txt file, (although, if that is the solution I would like a walk through cuz that is beyond my understanding and I don't want to mess things up.)

非常感谢任何帮助。

****工作解决方案(感谢m3tho;请参阅他们的评论以获得解释)

****Working Solution (thanks to m3tho; see their comments for explanation)

system ('java -jar C:\My\Java\Class\Path\To\MyJar.jar')


推荐答案

我能想到的最简单的解决方案是在系统命令中执行jar:

The simplest solution I can think of is to execute the jar in a system command with:

system('java -jar MyJar.jar')

这种方式适用于任何操作系统,无需任何解决方法。

This way should work on any OS without any workaround.

这篇关于如何在Matlab中运行java .jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆