B4J Question Library selection based on Build configuration (not external jars)

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hello

This question is based on being able to use jserver3 or jserver4 based on a build condition. I am not referring to external jars, on the libraries in the Additional and Internal folders

Here is an example od what I currently do for mssql-jdbc
B4X:
#if java11
        #JavaCompilerPath: 19, C:\Java\jdk-19.0.2\bin\javac.exe    
        #AdditionalJar: C:\Java\jdbc\sqljdbc_12.8\enu\jars\mssql-jdbc-12.8.1.jre11.jar
    #else
        #JavaCompilerPath: 8, C:\Java\jdk1.8.0_351\bin\javac.exe
        #AdditionalJar: mssql-jdbc-6.2.2.jre8.jar
    #End If

You can see what is going on here. I was wondering is the another # directive to allow me user a library from addition or internal

Thanks in advance

John.
 

aeric

Expert
Licensed User
Longtime User
allow me user a library from addition or internal
I think both libraries must have different class name.
Just declare the object as usual.
B4X:
Sub Process_Globals
    #If Condition1
    Public MyObject As ClassFromAdditionalLibrary
    #Else
    Public MyObject As ClassFromInternalLibrary
    #End If
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
I think both libraries must have different class name.
Just declare the object as usual.
B4X:
Sub Process_Globals
    #If Condition1
    Public MyObject As ClassFromAdditionalLibrary
    #Else
    Public MyObject As ClassFromInternalLibrary
    #End If
This suggestion does not acheive my objective as the classname is the same for both.
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
This Wish from 2018 seems to relate to your question.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
This Wish from 2018 seems to relate to your question.
Loved your response to the reply ! I guess its similar. To sumerise, all I would like to do is to include a library without having to select it from the Libraries Manager Tab. Example:

#useLibrary: C:\B4X\B4J\Aditional Libraries\jServer-11.0.24.jar (@tchart)

By doing this the ide would treat this the same as if I selected it from the Libraries Manager Tab.
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
Thanks. :)

Yes, for your case you would simply do this:

B4X:
#if java11
    #AdditionalLibraries: path-to-dir-with-jServer3
#else
    #AdditionalLibraries: path-to-dir-with-jServer4
#End If

However, in fairness, two more things would need to happen if you compare to my suggestion. The first one is that the additionaldirs are additive, so you have the standard additional libraries, and then you add another dir (in the code above), which in this example contains only contains the jServer libraries. The second one is that you would have to enable all build configurations and actually enable the dirs for both cases.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
Yep, if you have the ability to include a library using #AdditionalLibraries, which can point to anywhere then you can configure till the heart is content (@Erel please :) )

slight correction

B4X:
#if java11
    #AdditionalLibraries: path-to-dir-with-jServer4
#else
    #AdditionalLibraries: path-to-dir-with-jServer3
#End If
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
Yep, if you have the ability to include a library using #AdditionalLibraries, which can point to anywhere then you can configure till the heart is content (@Erel please :) )
I fear that the majority of the forum members, with Erel being one of them, are deeply in the "just shove the lot into one dir and let the compiler sort it out, we don't need no stinkin' order or structure". (In my head I hear that said with the voice from someone working the docks around 1800.) I imagine it's a result of B4X mainly being used by hobbyists and smaller companies, where there are no real expectations of keeping things strict. That's what it looks like from where I'm standing, anyway. (And for the record: I'm represent a smaller company, but we do have expectations of keeping things strict and in order.)
 
Upvote 0

tchart

Well-Known Member
Licensed User
Longtime User
Yep, if you have the ability to include a library using #AdditionalLibraries, which can point to anywhere then you can configure till the heart is content (@Erel please :) )

slight correction

B4X:
#if java11
    #AdditionalLibraries: path-to-dir-with-jServer4
#else
    #AdditionalLibraries: path-to-dir-with-jServer3
#End If
You should probably add this to the Wishlist for B4J. I would like this too but I guess the issue is the intellisense for library objects wouldn’t populate if it was dynamic.
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
I would like this too but I guess the issue is the intellisense for library objects wouldn’t populate if it was dynamic.
I can't imagine that would be a problem. There would effectively be nothing different from enabling or disabling any library, which the intellisense handle just fine. I imagine the problem is rather that Erel simply dislikes the idea and had decided that there shall only be one dir for additional libraries.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I imagine the problem is rather that Erel simply dislikes the idea and had decided that there shall only be one dir for additional libraries.
Not at all. It is more of a technical challenge. It will be implemented at some point (the ability to reference libraries based on build configuration).
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
Not at all. It is more of a technical challenge. It will be implemented at some point (the ability to reference libraries based on build configuration).
That's nice to hear. Does this also mean you're, in principle, positive to the many wishes for having multiple dirs with additional libraries? Such as this one, for example:
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
Not sure...
For whatever it's worth, I do appreciate getting a response and that's it not a flat out no.

I'll see if I can post a new wish in the coming months where I try to make it as clear as possible why this would be a very nice feature for some developers.
 
Upvote 0
Top