B4J Question MergeLibraries: True

aaronk

Well-Known Member
Licensed User
Longtime User
HI,

When I run my B4J (non-UI) app it works while in debug mode.

I then run it in release mode on VPS it fails to connect to the MySQL server.

I then tried to run the B4J app in release mode from the IDE and it works.

I noticed that MergeLibraries is set to false.

I am using AdditionalJar files, and I can't remember if it required the MergeLibraries to be set to false or not.

#AdditionalJar: bcprov-jdk15on-154
#AdditionalJar: mysql-connector-java-5.1.27-bin.jar
#AdditionalJar: mariadb-java-client-3.5.0.jar

I then changed MergeLibraries to true, but shows the MySQL won't connect and times out. (event times out in the IDE while set to true)

Do I need to do something different to make it work when MergeLibraries is set to true ?

B4J Version: 10.00
Java Version: 14

Libraries were not merged into jar file.
The following libraries should be distributed in the libs folder:
B4XEncryption.jar JavaObject.jar jConnectionPool.jar jCore.jar jDateUtils.jar jMQTT.jar jNet.jar jRandomAccessFile.jar jServer.jar Json.jar jSQL.jar jStringUtils.jar c3p0-0.9.5.2.jar c3p0-oracle-thin-extras-0.9.5.2.jar mchange-commons-java-0.2.11.jar org.eclipse.paho.client.mqttv3-1.2.5.jar jserver/http2-common-11.0.9.jar jserver/http2-server-11.0.9.jar jserver/jetty-alpn-java-server-11.0.9.jar jserver/jetty-alpn-server-11.0.9.jar jserver/jetty-io-11.0.9.jar jserver/jetty-jakarta-servlet-api-5.0.2.jar jserver/jetty-jakarta-websocket-api-2.0.0.jar jserver/jetty-server-11.0.9.jar jserver/jetty-servlet-11.0.9.jar jserver/jetty-servlets-11.0.9.jar jserver/jetty-slf4j-impl-11.0.9.jar jserver/jetty-util-11.0.9.jar jserver/slf4j-api-2.0.0-alpha6.jar jserver/websocket-core-common-11.0.9.jar jserver/websocket-core-server-11.0.9.jar jserver/websocket-jakarta-client-11.0.9.jar jserver/websocket-jakarta-common-11.0.9.jar jserver/websocket-jakarta-server-11.0.9.jar jserver/websocket-jetty-api-11.0.9.jar jserver/websocket-jetty-common-11.0.9.jar jserver/websocket-jetty-server-11.0.9.jar jserver/websocket-servlet-11.0.9.jar jserver/jetty-http-11.0.9.jar jserver/jetty-security-11.0.9.jar jserver/http2-hpack-11.0.9.jar jserver/jetty-webapp-11.0.9.jar OkHttp.jar XMLBuilder.jar jXmlSax.jar okhttp-4.9.0.jar okio-2.8.0.jar okhttp-urlconnection-4.9.3.jar kotlin-stdlib-1.6.10.jar bcprov-jdk15on-154.jar mysql-connector-java-5.1.27-bin.jar mariadb-java-client-3.5.0.jar
 

teddybear

Well-Known Member
Licensed User
Libraries were not merged into jar file.
The following libraries should be distributed in the libs folder:
B4XEncryption.jar JavaObject.jar jConnectionPool.jar jCore.jar jDateUtils.jar jMQTT.jar jNet.jar jRandomAccessFile.jar jServer.jar Json.jar jSQL.jar jStringUtils.jar c3p0-0.9.5.2.jar c3p0-oracle-thin-extras-0.9.5.2.jar mchange-commons-java-0.2.11.jar org.eclipse.paho.client.mqttv3-1.2.5.jar jserver/http2-common-11.0.9.jar jserver/http2-server-11.0.9.jar jserver/jetty-alpn-java-server-11.0.9.jar jserver/jetty-alpn-server-11.0.9.jar jserver/jetty-io-11.0.9.jar jserver/jetty-jakarta-servlet-api-5.0.2.jar jserver/jetty-jakarta-websocket-api-2.0.0.jar jserver/jetty-server-11.0.9.jar jserver/jetty-servlet-11.0.9.jar jserver/jetty-servlets-11.0.9.jar jserver/jetty-slf4j-impl-11.0.9.jar jserver/jetty-util-11.0.9.jar jserver/slf4j-api-2.0.0-alpha6.jar jserver/websocket-core-common-11.0.9.jar jserver/websocket-core-server-11.0.9.jar jserver/websocket-jakarta-client-11.0.9.jar jserver/websocket-jakarta-common-11.0.9.jar jserver/websocket-jakarta-server-11.0.9.jar jserver/websocket-jetty-api-11.0.9.jar jserver/websocket-jetty-common-11.0.9.jar jserver/websocket-jetty-server-11.0.9.jar jserver/websocket-servlet-11.0.9.jar jserver/jetty-http-11.0.9.jar jserver/jetty-security-11.0.9.jar jserver/http2-hpack-11.0.9.jar jserver/jetty-webapp-11.0.9.jar OkHttp.jar XMLBuilder.jar jXmlSax.jar okhttp-4.9.0.jar okio-2.8.0.jar okhttp-urlconnection-4.9.3.jar kotlin-stdlib-1.6.10.jar bcprov-jdk15on-154.jar mysql-connector-java-5.1.27-bin.jar mariadb-java-client-3.5.0.jar
This is a log generated during compiling when MergeLibraries is false.
The MergeLibraries, its default value is true.
search key MergeLibraries to find out if it is set somewhere
 
Upvote 0

aminoacid

Active Member
Licensed User
Longtime User
HI,

When I run my B4J (non-UI) app it works while in debug mode.

I then run it in release mode on VPS it fails to connect to the MySQL server.

I then tried to run the B4J app in release mode from the IDE and it works.

I noticed that MergeLibraries is set to false.

I am using AdditionalJar files, and I can't remember if it required the MergeLibraries to be set to false or not.

#AdditionalJar: bcprov-jdk15on-154
#AdditionalJar: mysql-connector-java-5.1.27-bin.jar
#AdditionalJar: mariadb-java-client-3.5.0.jar

I then changed MergeLibraries to true, but shows the MySQL won't connect and times out. (event times out in the IDE while set to true)

Do I need to do something different to make it work when MergeLibraries is set to true ?

So it looks like when you run it in the IDE (debug mode) you are running it on a remote (development) computer and connecting remotely to the VPS that is hosting mySQL Server. But when you run it on the VPS (release mode), you are installing the JAR (+dependencies) on the VPS and connecting locally to the mySQL server. Is this correct?
Is the VPS a Linux or Windows system?
 
Upvote 1

aaronk

Well-Known Member
Licensed User
Longtime User
Is the VPS a Linux or Windows system?
VPS is Linux and hosted on AWS (EC2)
My Development machine is Windows 10 running in a VM on a MAC.

Using My Win10 VM I have B4J running and when I run my B4J app with MergeLibraries set to False, in Debug & Release mode it runs fine and connects to the MySQL server. Still using the IDE on my Win10 VM, if I set MergeLibraries to True, in both Debug & release it doesn't connect to the MySQL database.

So it looks like when you run it in the IDE (debug mode) you are running it on a remote (development) computer and connecting remotely to the VPS that is hosting mySQL Server. But when you run it on the VPS (release mode), you are installing the JAR (+dependencies) on the VPS and connecting locally to the mySQL server. Is this correct?
I am running the debug from the IDE on the local computer. Not running debug on the Linux server. I ran the debug on my computer during development and it was all working, then I created a release and put it on the Linux server but it failed, and that is when I noticed that I had MergeLibraries set to false, and when I change it to True it don't allow it to connect to the MySQL database.

MergeLibraries: True - creates a single jar with all the dependent libraries merges into this jar.

MergeLibraries: False - creates a jar with your code. All other libraries should be distributed separately to a folder named libs, next to your jar.
I had a feeling that is what it did, as I noticed the file size of the B4J app got bigger when MergeLibraries is set to True.
 
Upvote 0

aminoacid

Active Member
Licensed User
Longtime User
then I created a release and put it on the Linux server but it failed,

To me it looks like you can connect remotely from your development computer to the VPS, but not locally on the VPS. See if you can connect locally - On the VPS you can run TELNET to connect to the mySQL server. If the connection fails then that confirms the problem.
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
To me it looks like you can connect remotely from your development computer to the VPS, but not locally on the VPS. See if you can connect locally - On the VPS you can run TELNET to connect to the mySQL server. If the connection fails then that confirms the problem.
The connection side of things would be OK. I can connect using my Win10 development PC. The issue is when compiled in release mode while MergeLibraries is set to True.

I have done some more testing today. I found that I can connect to the database while the MergeLibraries is set to true, only while in debug mode.

Soon as I build the release version of the B4J app it fails and times out (while MergeLibraries is set to True). This is while running in release mode on my Win10 Development PC. I then copied it to the VPS and got the same result where it fails in release mode.

Soon as I change the MergeLibraries to False, it works in both debug and release mode on my Win10 Development PC, but it would require me to copy all the jar files to the VPS which I was hoping not to have to do.
 
Upvote 1

DonManfred

Expert
Licensed User
Longtime User
Post a log from when it runs in releasemode and crashes. Without log it is hard to give any advices...
The mysqlconnector you are using is a real old one (V3)... Try a newer one for mriadb (V8, 9)
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
2025-03-18 18:56:05.720:INFO :cmvl.MLog:MLog-Init-Reporter: MLog clients using slf4j logging.
2025-03-18 18:56:05.879:INFO :cmvc.C3P0Registry:main: Initializing c3p0-0.9.5.2 [built 08-December-2015 22:06:04 -0800; debug? true; trace: 10]
2025-03-18 18:56:05.946:INFO :cmvci.AbstractPoolBackedDataSource:main: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 20000, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> 1hge165b91aommto1kkuu7s|3a82f6ef, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> 1hge165b91aommto1kkuu7s|3a82f6ef, idleConnectionTestPeriod -> 600, initialPoolSize -> 3, jdbcUrl -> jdbc:mariadb://my.site.here/status?characterEncoding=utf8, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 1800, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 15, maxStatements -> 150, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, preferredTestQuery -> null, privilegeSpawnedThreads -> false, properties -> {password=******, user=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> true, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
db._initialize (java line: 142)
java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:77)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:690)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
at anywheresoftware.b4j.object.ConnectionPool.GetConnection(ConnectionPool.java:45)
at b4j.example.db._initialize(db.java:142)
at b4j.example.main._appstart(main.java:87)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at b4j.example.main.main(main.java:28)
Caused by: com.mchange.v2.resourcepool.TimeoutException: A client timed out while waiting to acquire a resource from com.mchange.v2.resourcepool.BasicResourcePool@78b66d36 -- timeout at awaitAvailable()
at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1467)
at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:644)
at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:554)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:758)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:685)
... 11 more

db:
Public Sub Initialize
   
    pool.Initialize("com.mysql.jdbc.Driver","jdbc:mariadb://my.site.here/status?characterEncoding=utf8",username,password)

    Dim sql As SQL = pool.GetConnection
   
    Try
        'work with sql
        sql.ExecNonQuery("SET sql_notes = 0")
        sql.ExecNonQuery($"CREATE TABLE IF NOT EXISTS status_data (
        id INT AUTO_INCREMENT PRIMARY KEY,
        service VARCHAR(255) Not Null UNIQUE,
        Heartbeat_Interval INT
        )"$)
    Catch
        'handle failure
        Log(LastException.Message)
    End Try 'ignore
    sql.Close
End Sub

I just tried updating to mysql-connector-j-9.2.0 but had the same error.
 
Upvote 1

teddybear

Well-Known Member
Licensed User
This error is timeout that you got connection from pool.
I guess, the server was running on your VPS when building the release version.
Try killing the sever on your VPS then building the release
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
This error is timeout that you got connection from pool.
I guess, the server was running on your VPS when building the release version.
Try killing the sever on your VPS then building the release

It has nothing to do with the database or VPS from what I can tell.

I understand that the connection times out. However why? There has to be something with the B4J app that is making it timeout.

The reason I say it has to do with the B4J app is because while the B4J is compiled in release mode and MergeLibraries is set to True then it fails to connect to the database. (this is while the B4J app is running on my Win10 development machine connecting to the VPS database.)

If the B4J app is compiled in release mode and MergeLibraries is set to False, then it works and connects to the database. (this is while the B4J app is running on my Win10 development machine connecting to the VPS database.)

I haven't touched the database or VPS during this test. If it was the database or VPS having the issue, then it wouldn't have worked if it was in release mode & MergeLibraries set to False, but in that mode it works.
 
Upvote 1

aaronk

Well-Known Member
Licensed User
Longtime User
I originally copied it to the VPS and found it wasn't working on it, and then I checked on my Win10 and found it wasn't working in release mode on that.

So, currently all my tests are done on my Win10 development machine.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Try to run java -jar youapp.jar from cmd see if it works?
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
SQL database is working, but not when using the B4J app.
 
Last edited:
Upvote 0

teddybear

Well-Known Member
Licensed User
db:
Public Sub Initialize
  
    pool.Initialize("com.mysql.jdbc.Driver","jdbc:mariadb://my.site.here/status?characterEncoding=utf8",username,password)

End Sub
You seem to be accessing mariadb with mysql driver . try using mariadb driver
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
Unfortunately it didn't make a difference. I think the only way for now is to set it to false and then add the libs folder.
 
Upvote 0
Top