W wl Well-Known Member Licensed User Longtime User Dec 25, 2017 #1 Hi, Is there a way in obtaining (in code) the full path and filename of the jar file that is running ? I would like to be able to put a configuration file next to the JAR file (with a different file extension). Thanks !
Hi, Is there a way in obtaining (in code) the full path and filename of the jar file that is running ? I would like to be able to put a configuration file next to the JAR file (with a different file extension). Thanks !
Harris Expert Licensed User Longtime User Dec 25, 2017 #2 Dim path as string = File.GetFileParent(filename). You should know your file name since you created it? Upvote 0
Dim path as string = File.GetFileParent(filename). You should know your file name since you created it?
W wl Well-Known Member Licensed User Longtime User Dec 25, 2017 #3 That's not what I meant. Indeed I know the filename of the JAR file, but since the JAR file can be put in any location (and the JAR file might be renamed as well), I would like to obtain the full path + filename of the running JAR. Thanks Upvote 0
That's not what I meant. Indeed I know the filename of the JAR file, but since the JAR file can be put in any location (and the JAR file might be renamed as well), I would like to obtain the full path + filename of the running JAR. Thanks
Harris Expert Licensed User Longtime User Dec 25, 2017 #4 I have no idea how one might interrogate some running jar to extract it's particulars... Interesting - if at all possible... Upvote 0
I have no idea how one might interrogate some running jar to extract it's particulars... Interesting - if at all possible...
Erel B4X founder Staff member Licensed User Longtime User Dec 25, 2017 #5 File.DirApp will return this path when the user clicks on the the jar or starts it with java -jar <yourjar> The only case where it will not return the correct path is if you run it from a different folder: java -jar SomeFolder\Maybe Another One\<your jar> Upvote 0
File.DirApp will return this path when the user clicks on the the jar or starts it with java -jar <yourjar> The only case where it will not return the correct path is if you run it from a different folder: java -jar SomeFolder\Maybe Another One\<your jar>
W wl Well-Known Member Licensed User Longtime User Dec 25, 2017 #6 Thanks, but as I'm running the application inside a Linux shell ... This is what I found in Java fora ... can this be embedded in B4J ? B4X: return new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()); Upvote 0
Thanks, but as I'm running the application inside a Linux shell ... This is what I found in Java fora ... can this be embedded in B4J ? B4X: return new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
W wl Well-Known Member Licensed User Longtime User Dec 25, 2017 #7 With inline java this seems to work: B4X: Dim obj As JavaObject = Me Dim foo As String = obj.RunMethod("getRunningJAR", Null) Log (foo) and this as embedded Java: B4X: #if java static public String getRunningJAR() { try { return main.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath(); } catch (Exception e){ throw new RuntimeException(e); } } #End If Upvote 0
With inline java this seems to work: B4X: Dim obj As JavaObject = Me Dim foo As String = obj.RunMethod("getRunningJAR", Null) Log (foo) and this as embedded Java: B4X: #if java static public String getRunningJAR() { try { return main.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath(); } catch (Exception e){ throw new RuntimeException(e); } } #End If
W wl Well-Known Member Licensed User Longtime User Dec 26, 2017 #8 Note that when running in debug mode there is no JAR and the return value refers to the folder in which the main.class resides. Upvote 0
Note that when running in debug mode there is no JAR and the return value refers to the folder in which the main.class resides.