Iam是MATLAB的新手,希望在Java中使用一些MATLAB脚本。我已经尝试过来自MATLAB的这教程。我想在Java中使用的MATLAB函数:
function y = makesqr(x)
y = magic(x);这个MATLAB脚本应该打包到一个Java包中。但是,在创建二进制文件失败后,我会得到错误。而且,我可能还没有完全理解它的工作方式。我可以将MATLAB脚本编译成Java,Java包可以在Java代码中运行吗?
Iam使用Windows 64位与Java版本
1.8.0_121-b13Matlab
1.7.0_60-b19
Loading source files for package makesqr...
Constructing Javadoc information...
Standard Doclet version 1.8.0_121
Building tree for all the packages and classes...
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\makesqr\Class1.html...
C:\Users\Documents\MATLAB\makesqr\for_testing\makesqr\Class1.java:109: warning: no @param for args
public static void main (String[] args)
^
C:\Users\Documents\MATLAB\makesqr\for_testing\makesqr\Class1.java:59: warning: no @throws for com.mathworks.toolbox.javabuilder.MWException
public Class1() throws MWException
^
C:\Users\Documents\MATLAB\makesqr\for_testing\makesqr\Class1.java:88: warning: no @throws for com.mathworks.toolbox.javabuilder.MWException
public Class1(MWComponentOptions componentOptions) throws MWException
^
C:\Users\Documents\MATLAB\makesqr\for_testing\makesqr\Class1.java:77: warning: no @throws for com.mathworks.toolbox.javabuilder.MWException
public Class1(String pathToComponent) throws MWException
^
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\makesqr\Class1Remote.html...
C:\Users\Documents\MATLAB\makesqr\for_testing\makesqr\Class1Remote.java:58: error: reference not found
* @throws java.jmi.RemoteException An error has occurred during the function call or
^
C:\Users\Documents\MATLAB\makesqr\for_testing\makesqr\Class1Remote.java:61: warning: no @throws for java.rmi.RemoteException
public Object[] makesqr(int nargout, Object... rhs) throws RemoteException;
^
C:\Users\Documents\MATLAB\makesqr\for_testing\makesqr\Class1Remote.java:64: warning: no @throws for java.rmi.RemoteException
void dispose() throws RemoteException;
^
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\makesqr\MakesqrMCRFactory.html...
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\makesqr\package-frame.html...
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\makesqr\package-summary.html...
C:\Users\Documents\MATLAB\makesqr\for_testing\makesqr\package-info.java:8: warning: empty
tag
*
^
C:\Users\Documents\MATLAB\makesqr\for_testing\makesqr\package-info.java:15: error: unexpected end tag:
*
^
C:\Users\Documents\MATLAB\makesqr\for_testing\makesqr\package-info.java:20: warning: empty
tag
*
^
C:\Users\Documents\MATLAB\makesqr\for_testing\makesqr\package-info.java:26: error: unexpected end tag:
*
^
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\makesqr\package-tree.html...
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\constant-values.html...
Building index for all the packages and classes...
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\overview-tree.html...
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\index-all.html...
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\deprecated-list.html...
Building index for all classes...
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\allclasses-frame.html...
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\allclasses-noframe.html...
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\index.html...
Generating C:\Users\Documents\MATLAB\makesqr\for_testing\doc\html\help-doc.html...
3 errors
8 warnings
Error: An error occurred while shelling out to javadoc (error code = 1).
Unable to build executable. For more information, pass the -v option to mcc.发布于 2017-03-08 15:28:30
我的解决方案是使用Java 7而不是Java 8,Matlab不支持Java 8。
安装Java并设置JAVA_HOME路径。这里是一个很好的描述
发布于 2017-09-09 11:45:11
为了能够使用MATLAB编译器将MATLAB文件打包到Java库中,必须安装和配置MATLAB使用的相同版本的JDK。通过运行以下MATLAB命令,可以获得MATLAB安装使用的Java版本:
version -java此外,必须正确设置JAVA_HOME环境变量。配置Java环境页面包含更多信息。
https://stackoverflow.com/questions/42644580
复制相似问题