使用 MATLAB 编译器将 MATLAB 转换为 Java
MATLAB to Java with MATLAB compiler
我是 MATLAB 的新手,想在 Java 中使用一些 MATLAB 脚本。
我试过来自 MATLAB 的 this 教程。
我想在 Java:
中使用我的 MATLAB 函数
function y = makesqr(x)
y = magic(x);
此 MATLAB 脚本应打包到 Java 包中。
但是在创建二进制文件失败后出现错误。
此外,我可能还没有完全理解它的工作方式。
我可以将 MATLAB 脚本编译为 Java,Java 包可以在 Java 代码中 运行 ?
我正在使用 Windows 64 位 Java 版本
1.8.0_121-b13
Matlab 有
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.
我的解决方案是使用 Java JDK 7 而不是 Java 8。
Matlab不支持Java 8.
安装JavaJDK并设置JAVA_HOME路径。
Here 是一个很好的描述
为了能够使用 MATLAB Compiler 将 MATLAB 文件打包到 Java 库中,必须安装和配置与 MATLAB 使用相同版本的 JDK。 MATLAB 安装使用的 Java 版本可以通过 运行 以下 MATLAB 命令获得:
version -java
此外,JAVA_HOME
环境变量必须正确设置。 Configure Your Java Environment 页面包含更多信息。
我是 MATLAB 的新手,想在 Java 中使用一些 MATLAB 脚本。 我试过来自 MATLAB 的 this 教程。 我想在 Java:
中使用我的 MATLAB 函数 function y = makesqr(x)
y = magic(x);
此 MATLAB 脚本应打包到 Java 包中。 但是在创建二进制文件失败后出现错误。 此外,我可能还没有完全理解它的工作方式。 我可以将 MATLAB 脚本编译为 Java,Java 包可以在 Java 代码中 运行 ?
我正在使用 Windows 64 位 Java 版本
1.8.0_121-b13
Matlab 有
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.
我的解决方案是使用 Java JDK 7 而不是 Java 8。 Matlab不支持Java 8.
安装JavaJDK并设置JAVA_HOME路径。 Here 是一个很好的描述
为了能够使用 MATLAB Compiler 将 MATLAB 文件打包到 Java 库中,必须安装和配置与 MATLAB 使用相同版本的 JDK。 MATLAB 安装使用的 Java 版本可以通过 运行 以下 MATLAB 命令获得:
version -java
此外,JAVA_HOME
环境变量必须正确设置。 Configure Your Java Environment 页面包含更多信息。