Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Javaaddpath May Not Work Properly Due to Search Location #4

Open
TheOriginalMrClean opened this issue Aug 10, 2018 · 1 comment
Open

Comments

@TheOriginalMrClean
Copy link

TheOriginalMrClean commented Aug 10, 2018

If the end file location is not in the current working directory of MATLAB, ReadYamlRaw() and WriteYaml() may not properly import snakeyaml because the javapath was not added correctly.

This is due to these lines:

 [pth,~,~] = fileparts(filename);
...

...
if not(ismember(dp, javaclasspath ('-dynamic')))
       javaaddpath(dp); % javaaddpath clears global variables...!?
end

Notice how the script is looking at the current directory of the file rather than the current working directory.

@TheOriginalMrClean
Copy link
Author

The above issue can be fixed by the following code replacing the if statement above:

if not(ismember(dp, javaclasspath ('-dynamic')))
       javaaddpath(dp); % javaaddpath clears global variables...!?
            
elseif not(ismember(fullfile(pwd,'external\snakeyaml-1.9.jar'),javaclasspath ('-dynamic')))
       javaaddpath(fullfile(pwd,'external\snakeyaml-1.9.jar'));
end

I would recommend each user check this and if the user is going to be using ReadYaml() and WriteYaml() in a specific way (for instance, I will always have the ReadYaml() and WriteYaml() in a folder which the external folder containing snakeyaml-1.9.jar is inside. Therefore, the above code always should work.

I swapped the order which the code checks locations to improve speed for myself, but checking the output/input file directory first also works. Either way, I would recommend checking the working directory be standard implementation, while users be encouraged to add other locations for their various arrangements of files. If they so choose, they could also do a search for the file within or around the current working directory. However, that is obviously costly for processing time.

@TheOriginalMrClean TheOriginalMrClean changed the title Addpath May Not Work Properly Javaaddpath May Not Work Properly Due to Search Location Aug 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant