1function jar_path = lineDownloadJAR(verbose)
2% LINEDOWNLOADJAR Download jline.jar from SourceForge
if not found locally.
4% jar_path = lineDownloadJAR()
5% jar_path = lineDownloadJAR(verbose)
7% Downloads jline.jar from SourceForge (https:
8% and places it in
the common/ directory (auto-discovered or current repo).
9% Returns
the path to
the JAR after download.
12% verbose (optional): If true, print status messages (default: true)
15% jar_path: Full path to jline.jar
18% jar_path = lineDownloadJAR(); % Auto-download and set up
19% jar_path = lineDownloadJAR(
false); % Silent mode
21if nargin < 1 || isempty(verbose)
25% 1. Try to locate existing jline.jar
26existing_jar = which(
'jline.jar');
27if ~isempty(existing_jar) && isfile(existing_jar)
29 fprintf(
'jline.jar already found at: %s\n', existing_jar);
31 jar_path = existing_jar;
35% 2. Try to find/create common/ directory
36repo_root = lineGetRepoRoot();
41common_dir = fullfile(repo_root,
'common');
45 fprintf(
'Created directory: %s\n', common_dir);
49jar_path = fullfile(common_dir,
'jline.jar');
51% 3. Check
if already downloaded to common/
54 fprintf(
'jline.jar found in common/: %s\n', jar_path);
56 addPathIfNeeded(common_dir);
60% 4. Get version from GlobalConstants.java (works on all OS)
61repo_root = lineGetRepoRoot();
62gc_file = fullfile(repo_root,
'jar',
'src',
'main',
'java',
'jline',
'GlobalConstants.java');
67 content = fileread(gc_file);
68 % Extract version string: Version =
"X.Y.Z"
69 % Use character arrays
for cross-platform compatibility
70 tokens = regexp(content,
'Version\s*=\s*"([^"]+)"',
'tokens');
71 if ~isempty(tokens) && ~isempty(tokens{1})
72 version =
char(tokens{1}{1});
75 % Silently
continue if version extraction fails
79% 5. Download versioned jar from SourceForge
81 % Fallback: download
generic jline.jar
if version detection fails
82 versioned_jar_path =
'';
83 jar_url =
'https://line-solver.sourceforge.net/latest/jline.jar';
84 jar_filename =
'jline.jar';
86 fprintf(
'Version detection failed; will download generic jline.jar\n');
89 jar_filename = sprintf(
'jline-%s.jar', version);
90 versioned_jar_path = fullfile(common_dir, jar_filename);
91 jar_url = sprintf(
'https://line-solver.sourceforge.net/latest/%s', jar_filename);
95 fprintf(
'Downloading %s from: %s\n', jar_filename, jar_url);
96 fprintf(
'Target: %s\n', jar_path);
100 % Check
if versioned jar already exists (cross-platform)
101 if ~isempty(versioned_jar_path) && isfile(versioned_jar_path)
103 fprintf(
'Found existing %s\n', jar_filename);
106 % Copy versioned jar to
generic jline.jar (works on all OS)
107 copyfile(versioned_jar_path, jar_path);
109 fprintf(
'Linked: %s -> jline.jar\n', jar_filename);
113 % Download from SourceForge (websave works on all OS)
114 options = weboptions(
'Timeout', 60,
'ContentType',
'auto');
115 websave(jar_path, jar_url, options);
118 error(
'lineDownloadJAR:DownloadFailed',
'Download completed but file not found');
121 file_info = dir(jar_path);
123 fprintf(
'Downloaded jline.jar (%.1f MB)\n', file_info.bytes / (1024*1024));
126 % If we downloaded versioned jar, also copy to common name
127 if ~isempty(versioned_jar_path) && ~isequal(jar_path, versioned_jar_path)
128 copyfile(jar_path, versioned_jar_path);
130 fprintf(
'Also saved as: %s\n', jar_filename);
136 error(
'lineDownloadJAR:DownloadFailed',
'Failed to set up jline.jar');
139 % Add to MATLAB path
if not already there
140 addPathIfNeeded(common_dir);
143 % Clean up partial files
if download failed (safe on all OS)
150 if ~isempty(versioned_jar_path) && isfile(versioned_jar_path)
152 delete(versioned_jar_path);
157 error(
'lineDownloadJAR:DownloadFailed', ...
158 [
'Failed to download jline.jar from SourceForge:\n', ...
159 ME.message,
'\n\n', ...
161 '1. Download manually: https://line-solver.sourceforge.net/latest/jline.jar\n', ...
162 '2. Build locally: cd jar && mvn clean package -P b\n', ...
163 '3. Set JLINE_JAR environment variable to point to existing jar']);
168% -----------------------------------------------------------------------
169function repo_root = lineGetRepoRoot()
170% Try to find
the LINE repository root by searching
for key markers.
173% Start from
this file
's location
174this_file = mfilename('fullpath
');
175search_dir = fileparts(fileparts(fileparts(this_file)));
177% Walk up looking for markers (jar/, matlab/, python/ subdirs)
179 if isfolder(fullfile(search_dir, 'jar
')) && ...
180 isfolder(fullfile(search_dir, 'matlab
')) && ...
181 isfolder(fullfile(search_dir, 'python
'))
182 repo_root = search_dir;
185 parent = fileparts(search_dir);
186 if strcmp(parent, search_dir)
194% -----------------------------------------------------------------------
195function addPathIfNeeded(dir_path)
196% Add directory to MATLAB path if not already there
198if ~contains(current_paths, dir_path)