调用Matlab从Java,java.lang.UnsatisfiedLinkError。

huangapple go评论44阅读模式
英文:

Calling matlab from java, java.lang.UnsatisfiedLinkError

问题

我正在尝试从Java(在Eclipse中开发)调用我拥有的Matlab函数。我可以在R2019b中成功运行它,但是当我将Java构建路径更改为R2019a(engine.jar - C:\Program Files\MATLAB\R2019a\extern\engines\java\jar)时,出现错误:

Caused by: java.lang.UnsatisfiedLinkError: com.mathworks.mvm.MvmFactory.nativeSetJavaEngine(Z)V
	at com.mathworks.mvm.MvmFactory.nativeSetJavaEngine(Native Method)
	at com.mathworks.mvm.MvmImpl.setJavaEngineMode(MvmImpl.java:203)
	at com.mathworks.engine.MatlabEngine.<clinit>(MatlabEngine.java:69)
	at MyController.onRunSimClick(MyController.java:190)
	... 62 more

我已将C:\Program Files\MATLAB\R2019b\bin\win64和C:\Program Files\MATLAB\R2019a\bin\win64都添加到我的PATH变量中。

堆栈跟踪的开始部分是:

java.lang.NoSuchMethodError: Method com.mathworks.mvm.MvmFactory.nativeCreateFactory(IIZ[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;)J not found

我愿意提供剩下的部分,但不想创建混乱。提前感谢!

英文:

I am trying to call a matlab function I have from java (developing in Eclipse). I can get it to run just fine with R2019b, but when I change the java build path to R2019a (engine.jar - C:\Program Files\MATLAB\R2019a\extern\engines\java\jar), I get an error:

Caused by: java.lang.UnsatisfiedLinkError: com.mathworks.mvm.MvmFactory.nativeSetJavaEngine(Z)V
	at com.mathworks.mvm.MvmFactory.nativeSetJavaEngine(Native Method)
	at com.mathworks.mvm.MvmImpl.setJavaEngineMode(MvmImpl.java:203)
	at com.mathworks.engine.MatlabEngine.&lt;clinit&gt;(MatlabEngine.java:69)
	at MyController.onRunSimClick(MyController.java:190)
	... 62 more

I have added both C:\Program Files\MATLAB\R2019b\bin\win64 and C:\Program Files\MATLAB\R2019a\bin\win64 to my PATH variable.

The start of the stack trace is:

java.lang.NoSuchMethodError: Method com.mathworks.mvm.MvmFactory.nativeCreateFactory(IIZ[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;)J not found

I am happy to provide the rest, but don't want to create clutter. Thanks in advance!

答案1

得分: 0

我不能评论,所以将这个作为一个答案。你可能想要做的第一件事是运行:

java -XshowSettings:properties -version

以查看你的java.library.path是什么。

英文:

I cannot comment yet, so putting this in as an answer. The first thing you might want to do is run:

java -XshowSettings:properties -version

to see what your java.library.path is.

答案2

得分: 0

我找到了一个解决方法,我只需要从命令行编译和运行我的代码。在任何其他Matlab版本之前,我必须将C:\Program Files\MATLAB\R2019a\bin\win64;添加到我的路径中。然后,根据Matlab文档,我可以这样做:

> javac -classpath matlabroot\extern\engines\java\jar\engine.jar MyJavaCode.java
> java -classpath .;matlabroot\extern\engines\java\jar\engine.jar MyJavaCode

我仍然不确定为什么这在Eclipse中无法工作,但这个解决方法将在短期内起作用。

英文:

I found a workaround, where I can just compile and run my code from the command line. I had to add C:\Program Files\MATLAB\R2019a\bin\win64; to my path before any other matlab version. Then, as per the matlab documentation I could just do:

&gt; javac -classpath matlabroot\extern\engines\java\jar\engine.jar MyJavaCode.java
&gt; java -classpath .;matlabroot\extern\engines\java\jar\engine.jar MyJavaCode

I'm still not sure why this wouldn't work in Eclipse, but this workaround will work for the short term.

huangapple
  • 本文由 发表于 2020年7月22日 01:14:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/63019647.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定