My source code runs in the JAR file (for example, foo.jar). At this time, I want to know what folder the running foo.jar is in in the source code.
So if there is foo.jar in C:\FOOO\
, I would like to know the location information of the JAR file regardless of the execution location.
return new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
However, this may cause strange results if you load something other than a file type.
© 2024 OneMinuteCode. All rights reserved.