B4J Question File.DirApp yields current directory, not .jar directory, in Linux

GTBecker

Member
Licensed User
If a B4J-compiled .jar is run in Linux (LMDE/Debian7 w/JRE 8u20) the current directory matters. If the current directory is that of the .jar all is good but, if not - even if a complete path to the .jar is supplied at invocation - function File.DirApp yields the current directory, not that of the .jar. Consequently, in example ServerHelloWorld, www/ and index.html aren't found so the app yields a 404 to client machines. This also happens on a RaspberryPi (Raspian) with the current JRE for ARM.

Why? What is a remedy?

Tom
 

Erel

Administrator
Staff member
Licensed User
File.DirApp returns the user working directory. This value is returned from the JVM, it is stored under user.dir system property.

In most cases it will be the jar folder as the user double clicks on the jar. However if you run it from the command line and you run it from a different folder then it will be a different folder. It should behave this way on all OSs.

If you want to run it from a script then you need to change the current directory to the jar file directory and then run it.
 
Upvote 0

johnB

Active Member
Licensed User
Am I missing something here.
I've copied my .jar to a folder in Dropbox and when I run it from there and Log File.DirApp it gives me the folder that the .jar file was compiled to, not the current folder that the .jar resides, which is the one I want

(Didn't want to start a new thread for something already covered here)
 
Upvote 0
Top