B4J Question Process_Globals in external Jar

tchart

Well-Known Member
Licensed User
Longtime User
Im not sure if this is related to 5.9 Beta 1 or not. I am compiling a project to a library.

I have two variables defined in Process_Globals in a code module.

B4X:
Sub Process_Globals
    Dim SQLDirectory As String = File.DirApp
    Dim SQLFileName As String = "esri_patches.sqlite" 
End Sub

However Im getting a file not found exception when I try to access the sqlite file. I tried to log the variables but the variables dont show in the Log.

I reviewed the derived Java code and the resulting JAR and the global variables are set to empty!

See the attached file.

Capture.PNG
 

tchart

Well-Known Member
Licensed User
Longtime User
Ah actually I do see at the end of the class code the variables are set but for some reason they are empty when I try to access them.

B4X:
  public static String _process_globals()
    throws Exception
  {
    _sqldirectory = File.getDirApp();
   
    _sqlfilename = "esri_patches.sqlite";
   
    return "";
  }
 
Upvote 0

tchart

Well-Known Member
Licensed User
Longtime User
Can you upload the library?

@Erel here you go, sorry about the delay. To explain, the web server project loads a Jar (b4j library) at run time and creates a background worker thread. The background worker calls a sub in a code module and its that process globals which arent being set.
 

Attachments

  • test_for_erel.zip
    8 KB · Views: 172
Upvote 0

tchart

Well-Known Member
Licensed User
Longtime User
@Erel, I've split my web server project into separate b4j libraries that I load at runtime (when the server starts). I've done this to make it easier to maintain the code and be able to deploy individual updates to the libraries rather than a 100mb jar file (like I used to).

The jarLoader works as far as I can tell as the library/jar is loaded and I can add the background thread class, handler classes, filters etc.

I suspect the issue may be a limitation of the approach. I dont know the lifecycle of Process Globals. Maybe because there is no process there is no Process Globals for the loaded library or the class path is wrong - but I can call DoUpdate just fine so I dont know.

I've got a work around for now but it would be good to know either if its a bug or limitation of the way Im doing things.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've done this to make it easier to maintain the code and be able to deploy individual updates to the libraries rather than a 100mb jar file (like I used to).
This is not the correct solution.

The correct solution is to set #MergeLibraries to False and then upload the libraries. This allows you to update whichever library you like separately.
 
Upvote 0

tchart

Well-Known Member
Licensed User
Longtime User
This is not the correct solution.

The correct solution is to set #MergeLibraries to False and then upload the libraries. This allows you to update whichever library you like separately.

Thanks Erel, just to point out the libraries Im referring to are not classic b4j libraries per se (not like jdbc etc). The project that becomes the library Im referring to is just an empty main with a collection of web Server Handlers, Server Filters and Standard Classes (for background threads). It does not add functionality like a normal library it just separates my main web server project from the handlers and makes it easy to update the handlers in isolation.

As far as I can see there isn't a way to do this with normal b4j libraries, hence the solution to load the jars at runtime.

If there is another way to do this I'd happily listen to any advice.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've moved the thread to the questions forum.

Unless I'm missing something I don't understand why do you need to do anything special to load the libraries.

Compile the relevant project to a library and then reference that library in the server project. That's all.
Make sure that #MergeLibraries is set to False if you want to be able to update each jar separately.
 
Upvote 0

tchart

Well-Known Member
Licensed User
Longtime User
@Erel, thanks I modified the project I posted to load the library as you suggested and you the process globals can be accessed! I will change my approach.

As an aside, do you know why one method would work and not the other? The behaviour seems specific to process globals as I can access other functions in the classes from the loaded library. So its a bit odd.
 
Upvote 0

tchart

Well-Known Member
Licensed User
Longtime User
Oh I see it now, the main class is calling initializeProcessGlobals() which is calling my_code_module._process_globals();

So yes a limitation of what Im doing...
 
Upvote 0
Top