1

I have the following lines in my MATLAB code:

javaaddpath('C:\Users\localadmin\SkyDrive\IdeaProjects\DrawModels\out\artifacts\DrawModels_jar\DrawModels.jar') javaaddpath('C:\Users\localadmin\SkyDrive\IdeaProjects\DrawModels\out\artifacts\DrawModels_jar\itextpdf-5.4.1.jar') 

I then go on to instantiate some JAVA objects defined in the files.

I would like to copy the JAR files to where the .m file sits, and then write the following instead (i.e. I want to use a relative path rather than an absolute one).

javaaddpath('DrawModels.jar') javaaddpath('itextpdf-5.4.1.jar') 

However, the MATLAB path doesn't seem to apply to javaaddpath and so the JAR files do not get loaded.

Any ideas as to how I may achieve a relative path addressing of JAR files?

The background for this is I want the MATLAB code to run both on Windows and Linux, i.e. whereever it is unpacked. The user may unpack it in any folder he chooses, so I don't want a hard-coded path in the source.

Any help appreciated.

1 Answer 1

1

You can use mfilename to find the path of the running M file, which you can concatenate with the JAR file name like,

javaaddpath(fullfile(fileparts(mfilename('fullpath')),'DrawModels.jar')) 

That must go in the M file with which you would like to add the Java class to MATLAB.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.