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

8 views (last 30 days)
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".

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 22 Jan 2010
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 Comment
Titus Edelhofer
Titus Edelhofer on 25 Mar 2015
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

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R14SP1

Community Treasure Hunt

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

Start Hunting!