-
Notifications
You must be signed in to change notification settings - Fork 4
/
add_poi_path.m
63 lines (50 loc) · 1.91 KB
/
add_poi_path.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
%Add Apache POI library to MATLAB's static Java class path
%
%EXAMPLE USAGE
% >> add_poi_path
%
%INPUT
% segment - if '-static', add POI library .jar files to the static path; if
% '-dynamic', add to the dynamic path. {default: '-static'}
%
%VERSION DATE: 20 November 2017
%AUTHOR: Eric Fields
%
%NOTE: This function is provided "as is" and any express or implied warranties
%are disclaimed.
%Copyright (c) 2017, Eric Fields
%All rights reserved.
%This code is free and open source software made available under the 3-clause BSD license.
function add_poi_path(segment)
%Default to updating static path
if ~nargin
segment = '-static';
end
%Get full path for POI .jar files not on static Java class path
[~, missing_poi_files] = get_poi_paths();
%Nothing to do if all files are on static path
if isempty(missing_poi_files)
return;
end
if strcmpi(segment, '-static')
%Full path for javaclasspath file
static_file = [prefdir filesep 'javaclasspath.txt'];
%Append missing POI files to javaclasspath.txt file
f_out = fopen(static_file, 'a');
for i = 1:length(missing_poi_files)
fprintf(f_out, '%s\n', missing_poi_files{i});
end
fclose(f_out);
%POI files will not actually be added to the Java class path until
%MATLAB is restarted
msgbox('Close and restart MATLAB to finish adding the Apache POI library to the Java class path.')
elseif strcmpi(segment, '-dynamic')
%Add any file no on the static or dynamic path to the dynamic path
for i = 1:length(missing_poi_files)
jar_file = missing_poi_files{i};
if ~ismember(jar_file, javaclasspath('-dynamic'))
javaaddpath(jar_file);
end
end
end
end