What is the best practice for referencing a full file path in my deployed application?

조회 수: 17 (최근 30일)
I am creating a compiled application using MATLAB Compiler, and want to make sure I'm following good pathing practices. I was reading the blog post here, which says that a compiled application behaves more consistently if it uses relative paths (or anchors paths to a known root via matlabroot or ctfroot functions).
In my application, I need to make a connection to a JDBC database. This requires configuring a JDBCConnectionOptions object, which takes in the full file path to the JDBC driver as an input argument, so I need to be able to reference the full file path. I have included the JDBC driver in my compiled application, and know the relative path of the file.
I tried following the instructions in the blog post which suggest using paths relative to the ctfroot; however, in newer (R2018b+) releases of MATLAB you cannot do this in the same way (the directory structure for compiled apps has changed and there is now an additional sub-directory between the ctfroot and the files included with the compiled application).
How can I go about referencing the full path for my JDBC driver in the deployed app?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2020년 5월 8일

You are correct that the folder structure has changed from R2018b forward.

In general, the best practice to use when referencing files included in the CTF is to use just the filename, as all files that you include with your application are added to your application's path. However, in cases where this is not possible (e.g. you need to specify a full file path as a function argument), you can do the following:

Use the which function to locate your desired JDBC file on the MATLAB path. For instance, if you include the 'mysql-connector-java-8.0.20.jar' file in your compiled application, you can find the full file path in your compiled application by executing:

>> driverPath = which('mysql-connector-java-8.0.20.jar');

You can then pass the resulting driverPath variable as an input to the setConnectionOptions function.

  댓글 수: 3
Kautuk
Kautuk 2025년 12월 16일 8:04
Hello @cr, you can contact MathWorks Technical Support who may be able to assist you better: https://www.mathworks.com/support/contact_us.html
cr
cr 대략 24시간 전
MW tech support, at least in this region, do not honour their legal commitments of supporting installation issues with compiler/compiled products on perpetual licences without up to date on maintenance. This is is not even an installation issue, I'm certain it would be waste of time.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Application Deployment에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by