B4J Question Running a UI Java app in non-UI mode

yo3ggx

Active Member
Licensed User
Longtime User
Hi.

I've developed a Java app with B4J in two versions: non-UI and UI based.
There is any possibility to keep only one source code for both (with directives) or to run the UI version in non-UI mode using a command line switch, in order to have a single jar file?

There is anyway to change the first line from the source code (.b4j file) from
AppType=StandardJava
to
AppType=JavaFX
from the IDE, maybe through a compiler directive?

Thank you.
Dan
 
Last edited:

yo3ggx

Active Member
Licensed User
Longtime User
I want to run in non-UI mode on a Raspberry Pi (with no JavaFX). Is this possible if the application is built in UI-mode?
For me is better to build a separate jar only for non-UI mode.
Using compiler directives, I've merged the two source code, but in order to compile one or the other I have to manually edit "app.b4j" file to change AppType parameter, otherwise I get the error:
java.lang.Exception: Sub appstart signature does not match expected signature because in non-UI mode I have:
Sub AppStart (Args() As String)
but in UI mode:
Sub AppStart (Form1 As Form, args() As String)
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
For me is better to build a separate jar only for non-UI mode.
In that case you should create two projects and put all the modules except of the main module in the shared modules folder.

You can use the UI conditional symbol to exclude code that is only supported in UI projects. Check OkHttpUtils2 source code for an example.
 
Upvote 0

yo3ggx

Active Member
Licensed User
Longtime User
I have a single source code now and everything seems to be ok, except the fact that I have to manually change the AppType in the b4j file before opening the project.
There is any way to do this from the IDE?
Thank you.
Dan
 
Upvote 0

yo3ggx

Active Member
Licensed User
Longtime User
I've done it like that and everything is ok now.
In the main module there is just the AppStart(...) routine , all the rest is in the static code module.
Even AppStart calls a routine from the same code module.
Thank you.
Dan
 
Upvote 0
Top