B4J Question Best practice for organizing App Folders (Interpretted and Compiled)

Kevin L. Johnson

Licensed User
Longtime User
I am working through setting up a folder hierarchy for development and deployed operations of my B4J App. Ultimately, I will have a folder for templates (\templates), a folder for data (\data), and a folder for reports (\reports) etc.. How do i ensure this hierarchy works the same when under development in the IDE as when compiled and deployed?

I really like the idea that the compiled app can just be off of a thumb-drive without needing to be installed with registry entries etc. (It makes for simple and convenient running of the program on whatever pc you want). This means that the exe can reside anywhere and it simply runs.

With the additional footprint of the folder hierarchy, I am expecting that I simply need to put the executable in a folder that houses the hierarchy of folders and files used by the application and it too would run anywhere, the same, regardless of whether it was running under the developmental phase within the IDE or running anywhere else as a compile executable (in the folder with the additional folder hierarchy).

I am familiar with the special directories under the File object (File.DirAssets, including File.DirApp, File.DirData, and File.DirTemp) but these folders seem to spread my files out all over the drive (like "User\AppData\Roaming\MyApp" and a local "\Files directory" as so on.

Therefore, I am looking for the approach that keeps my executable along with a supporting folder hierarchy for data, templates, reports, etc. all within one overarching main folder AND it works the same under development within the IDE as it does when compiled and running within a folder on a thumb-drive.

\Top-level Folder
+---Jar file or exe app
+---\App Folder
+--------\Data Folder
+--------\Templates Folder
+--------\Reports Folder

Thoughts Anyone?
Last edited:

Kevin L. Johnson

Licensed User
Longtime User
I think this should do it … This allows an app or program the ability to utilize a hierarchical folder structure for all resource / support files such as data, images, reports, templates, sound files etc. … to be used during the developmental phase and then later after compiling and releasing … simply copy your apps jar file (or exe) and the AppFiles folder from the "YourProjectsFolder\Objects\AppsFolder" which holds your \Data and \Images and \Templates or any other of your apps folders to a new folder of your choice located on a thumb-drive or hard-drive folder of your choice!

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Public MyPrgDir As String
    Public MyTextWriter As TextWriter
    Public MyTextReader As TextReader
    Private TextArea1 As TextArea
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    MyPrgDir = ".\"
'    File.MakeDir(MyPrgDir, "AppFiles\")
'    MyTextWriter.Initialize(File.OpenOutput(MyPrgDir & "AppFiles\", "TestData.txt", False))
'    MyTextWriter.WriteLine("This is the first line." )
'    MyTextWriter.WriteLine("This is the second line." )
'    MyTextWriter.WriteLine("This is the third line."  )
'    MyTextWriter.Close
    MyTextReader.Initialize(File.OpenInput(MyPrgDir & "AppFiles\", "TestData.txt"))
    TextArea1.Text  = _
        MyTextReader.ReadLine & CRLF & _
        MyTextReader.ReadLine & CRLF & _
End Sub

Last edited:
Upvote 0