How should I include a JAR file in my compiled application with MATLAB Compiler 4.1 (R14SP1)?
9 ビュー (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2010 年 1 月 22 日
コメント済み: Titus Edelhofer
2015 年 3 月 25 日
I use a Java class in my MATLAB code functions, either as a JDBC driver with Database Toolbox or using the MATLAB Java interface to create instances of the java class directly. When I compile my functions with MATLAB compiler, the Java classes cannot be located. With Database Toolbox I get the error message
JDBC Driver Error: oracle.jdbc.driver.OracleDriver. Driver Not Found/Loaded.
when using the MATLAB Java interface I receive the error
??? Undefined variable "oracle" or class "oracle.jdbc.driver.OracleDriver".
採用された回答
MathWorks Support Team
2010 年 1 月 22 日
In order to use a Java class in a compiled application, the JAR-file which contains the class or the CLASS-file need to be available on the deployment machine and the JAR-file or directory which contains the CLASS-file or package hierarchy need to be on the Java classpath in the deployed application.
The -a flag to the MCC command provides a simple mechanism to accomplish both of these requirements. When a JAR-file or CLASS-file is added with the -a flag, it will be added to the CTF-archive and when the application starts up, that JAR-file or CLASS-file will also be automatically added to the dynamic java classpath. If you are using DEPLOYTOOL instead of the MCC command, you can add the JAR-file or CLASS-file to the "Other files" folder.
The java classpath in the compiled application will not get updated correctly if you are using a CLASS-file which is part of a package but which is not in a JAR-file. This is because there is no way for DEPLOYTOOL or MCC to determine that the CLASS-file is part of a package. In this case you will need to manually modify the java classpath in the compiled application, for example by using JAVAADDPATH.
1 件のコメント
Titus Edelhofer
2015 年 3 月 25 日
You don't have to use the same location: copy the javaclasspath.txt together with the compiled application to your deployment computer. Edit the javaclasspath to change the location of the jar file. The compiled application will use this javaclasspath.txt then instead of the one that was included in the compiled process.
Titus
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で MATLAB Compiler についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!