@@ -144,10 +144,23 @@ private File getWorkingDirectory()
144
144
{
145
145
try
146
146
{
147
- final URL execUrl = getClass ().getProtectionDomain ().getCodeSource ().getLocation ();
148
- System .out .println ("execUrl = " + execUrl );
149
- final String decodedExecUrlPath = URLDecoder .decode (execUrl .getPath (), "UTF-8" );
150
- final File decodedExecFile = new File (new URI (decodedExecUrlPath ));
147
+ final String execUrlPath = getClass ().getProtectionDomain ().getCodeSource ().getLocation ().getPath ();
148
+ final String decodedExecUrlPath = URLDecoder .decode (execUrlPath , "UTF-8" );
149
+ // check if decodedExecUrlPath is really URL, newer Java versions 11 or 17 returns normal path
150
+ System .out .println ("decodedExecUrlPath = " + decodedExecUrlPath );
151
+ File decodedExecFile = null ;
152
+ try
153
+ {
154
+ decodedExecFile = new File (new URI (decodedExecUrlPath ));
155
+ }
156
+ catch (URISyntaxException | IllegalArgumentException excpt )
157
+ {
158
+ decodedExecFile = new File (decodedExecUrlPath );
159
+ }
160
+ if (decodedExecFile .getPath ().startsWith ("file:" ))
161
+ {
162
+ decodedExecFile = new File (decodedExecFile .getPath ().replaceFirst ("^file:" , "" ));
163
+ }
151
164
152
165
System .out .println ("decodedExecFile = " + decodedExecFile );
153
166
System .out .println ("decodedExecFile.getParentFile() = " + decodedExecFile .getParentFile ());
@@ -156,7 +169,7 @@ private File getWorkingDirectory()
156
169
157
170
return decodedExecFile .getParentFile ();
158
171
}
159
- catch (SecurityException | URISyntaxException | UnsupportedEncodingException excpt )
172
+ catch (SecurityException | UnsupportedEncodingException excpt )
160
173
{
161
174
return null ;
162
175
}
0 commit comments