B4J Question Building Standalone Packages

Kiumbe

Member
I want to build and package my jRDC to a .jar file so as i can install it on my linux server. After running Project>Build Standalone Package, B4J has created two items under the Objects folder; jRDC.jar and packager.json. Am not sure if i need the packager.json on my Linux server or the jRDC.jar application alone. I have tried copying the jRDC.jar in linux bin folder and running the application with java -jar /usr/local/bin/jRDC.jar and i get below response on terminal:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: b4j/example/main has been compiled by a more recent version of the Java Runtime (class file version 53.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)


Where am I failing the application as it compiles without any error?
This is my first try on running B4J after packaging to test production, am holding my breath...🤯

Thanks community
 
Solution
jRDC jar file now running smoothly on ubuntu server with mysql. The problem with my environment was that i ended up with two versions of jre(8 and 9), the system was not configured to select default jre. I executed sudo update-alternatives --config java and select number 2 with jre 9 and on running nohup java -jar /usr/local/bin/jRDC.jar, the server is now up and processing my querries fast and furious, am happy, thanks so much aeric, cheers cheers cheers!!

Kiumbe

Member
P/S: You do not need to Build Standalone Package, just compiled as jar in Release mode.
This means that if I compile in RELEASE mode, it will generate a single .jar file that I will use on my Linux machine? No installations required
 
Upvote 0

aeric

Expert
Licensed User
This means that if I compile in RELEASE mode, it will generate a single .jar file that I will use on my Linux machine? No installations required
Yes, non-UI app doesn't need to install. Just extract the JDK and call java from the JDK.
 
Upvote 0

Kiumbe

Member
Just extract the JDK and call java from the JDK
Sorry to ask, I download JDK version 11, extract the contents in a directory within Linux. How do I call java from the JDK? Should I install JDK 11 on Linux server to be able to run jRDC.jar? Thanks
 
Upvote 0

aeric

Expert
Licensed User
Sorry to ask, I download JDK version 11, extract the contents in a directory within Linux. How do I call java from the JDK? Should I install JDK 11 on Linux server to be able to run jRDC.jar? Thanks

In the Terminal, run the command:
B4X:
nohup {path_to_java}/bin/java -jar jRDC.jar > nohup.out &
path_to_java example is /home/kiumbe/java-11.0.1

nohup /usr/bin/java -jar jRDC.jar > nohup1.out &
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
I can't remember how I installed the java in my VPS. I am now calling java from /usr/bin/java and it is pointing to /etc/alternatives/java
Maybe you can check (if you are running ubuntu)

Try:
which java
and
java -version
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
But I thought you said not installing anything but just copying the JDK 11 folder on the linux machine, then calling the .jar from there?
Sorry, I confused with the desktop UI.
You need to install JDK 11 since the version you have in Linux is Java runtime 8 if you compile the jar using JDK 11.
 
Upvote 0

aeric

Expert
Licensed User
But using Jdk 11 from a folder without installation also works
Example: I extract the JDK 11 to /home/aeric/jdk-11.0.1

So if I type /home/aeric/jdk-11.0.1/bin/java -version, it will show openJDK version 11.0.1

And to run the jar, I type
nohup /home/aeric/jdk-11.0.1/bin/java -jar jRDC.jar > nohup2.out &
 
Last edited:
Upvote 0

Kiumbe

Member
So if I type /home/aeric/jdk-11.0.1/bin/java -version, it will show openJDK version 11.0.1
When i type this on terminal /usr/local/bin/jdk-11.0.1/bin/java -version
I get this bash: /usr/local/bin/jdk-11.0.1/bin/java: No such file or directory
 
Upvote 0

Kiumbe

Member
jRDC jar file now running smoothly on ubuntu server with mysql. The problem with my environment was that i ended up with two versions of jre(8 and 9), the system was not configured to select default jre. I executed sudo update-alternatives --config java and select number 2 with jre 9 and on running nohup java -jar /usr/local/bin/jRDC.jar, the server is now up and processing my querries fast and furious, am happy, thanks so much aeric, cheers cheers cheers!!
 
Upvote 0
Solution

aeric

Expert
Licensed User
When i type this on terminal /usr/local/bin/jdk-11.0.1/bin/java -version
I get this bash: /usr/local/bin/jdk-11.0.1/bin/java: No such file or directory
No, I mean you can extract the jdk into your /home/username directory, not to /usr directory.
 
Upvote 0

aeric

Expert
Licensed User
You need to use the Java download from
Linux - https://b4xfiles-4c17.kxcdn.com/b4j/linux_jdk-11.0.1.zip (Java 11)
or
Linux - https://b4xfiles-4c17.kxcdn.com/b4j/linux_jdk-14.0.1.zip (Java 14)

Read here: https://www.b4x.com/android/forum/threads/server-run-a-server-on-a-vps.60378/

P/S: You do not need to Build Standalone Package, just compiled as jar in Release mode.
Take note that for UI app you need the Java listed above which include openJFX. For non-UI app that run in terminal, you can use the Java install using apt-get or the jdk extracted from the zip file above.
 
Upvote 0

OliverA

Expert
Licensed User
Ok, let me install JRE 9
Why would you run JRE9? It’s not LTS. Is your Ubuntu server running an ancient version of Ubuntu? Ubuntu has a nifty header less 11 JRE that just installs what is necessary to run non-GUI server apps. Why are you not using that?
 
Upvote 0
Top