How should I include a JAR file in my compiled application with MATLAB Compiler 4.1 (R14SP1)?

조회 수: 8 (최근 30일)
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
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
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 CenterFile Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품


릴리스

R14SP1

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by