B4J Question Error when running JAR

aeric

Well-Known Member
Licensed User
I try to run the jar file from CMD and have this error:

c:\>java -jar "C:\Development\Job\Objects\job.jar" 0
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/organization/app/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(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)


I have tried set #MergeLibraries to True and False (include all jar files in libs folder) as described in "Inline Java intents work fine in IDE debug mode, not work in execute compiled file" but the result is still the same.

I have also tried to use launch4j and alternate command such as
java -cp C:\Development\Job\Objects\job.jar com.organization.app.main 0
but no success.
 

sorex

Expert
Licensed User
are you sure your %path% variable points to the latest jre folder?

enter

java -version

and

echo %path%

in a cmd dos box
 

aeric

Well-Known Member
Licensed User
B4X:
c:\>java -version

java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) Client VM (build 25.211-b12, mixed mode, sharing)

c:\>echo %path%
C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\windows\System32\OpenSSH\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\CrSSL\bin;c:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;c:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;c:\Program Files\Microsoft SQL Server\110\Tools\Binn\;c:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files\dotnet\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Users\aeric\AppData\Local\Microsoft\WindowsApps;
 

sorex

Expert
Licensed User
is your B4J paths pointed to a 1.8.0_211 JDK? or that alternative one
 
Last edited:

aeric

Well-Known Member
Licensed User
I am using other version C:\Java\jdk-11.0.1\bin\javac.exe
upload_2019-6-13_15-29-16.png
 

sorex

Expert
Licensed User
see if that JDK folder has a JRE folder with java.exe in it. copy that java.exe file to that C:\Program Files (x86)\Common Files\Oracle\Java\javapath junction point folder

maybe that makes it working again


or install the 11.0.1 JRE
 

aeric

Well-Known Member
Licensed User
B4X:
c:\Java\jdk-11.0.1\bin>java -version
openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)
 

aeric

Well-Known Member
Licensed User
see if that JDK folder has a JRE folder with java.exe in it. copy that java.exe file to that C:\Program Files (x86)\Common Files\Oracle\Java\javapath junction point folder

maybe that makes it working again


or install the 11.0.1 JRE
This cause :
B4X:
Error: could not open `c:\Program Files (x86)\Java\jre1.8.0_211\lib\jvm.cfg'
 

sorex

Expert
Licensed User
yeah, it's a totally different version it seems.

I guess it's better to change you path and put that

c:\Java\jdk-11.0.1\bin

folder as first thing inthere.


try in cmd

set %path%="c:\Java\jdk-11.0.1\bin";%path%

or change it via windows gui as I don't know if you can still change it via cmd
 

aeric

Well-Known Member
Licensed User
I use another command to run
B4X:
java --module-path C:\Java\jdk-11.0.1\javafx\lib --add-modules ALL-MODULE-PATH -jar "C:\Development\Job\Objects\job.jar"
 

aeric

Well-Known Member
Licensed User
Thanks. I have converted my app to non-UI version. My problem resolved. I use the openjdk 11.
 

Didier9

Active Member
Licensed User
I try to run the jar file from CMD and have this error:

c:\>java -jar "C:\Development\Job\Objects\job.jar" 0
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/organization/app/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
I get the same errors on my work machines.
The only way I have found to run the jar on those machines is with the Launch4J packager but that seems to only work with Oracle Java, not OpenSDK (or at least I have not found how to make it work yet with OpenJDK). Launch4J wants a link to the JRE and OpenSDK does not have a separate JRE. I had no luck at all with B4JPackager and B4Jpackager11 on those work machines (even though that works fine on my home machines)
 

aeric

Well-Known Member
Licensed User
I get the same errors on my work machines.
The only way I have found to run the jar on those machines is with the Launch4J packager but that seems to only work with Oracle Java, not OpenSDK (or at least I have not found how to make it work yet with OpenJDK). Launch4J wants a link to the JRE and OpenSDK does not have a separate JRE. I had no luck at all with B4JPackager and B4Jpackager11 on those work machines (even though that works fine on my home machines)
I get it working using the OpenJDK11 and calling a batch file in CMD for my non-ui app. I think it should work for JRE 1.8 and JDK 1.8 pair (Java 8). I prefer using OpenJDK because no installation needed (unzip to a folder) and download the zip file doesn't need to create an Oracle account.

Actually the scenario is like this. I developed a push notification server using B4J in my laptop using OpenJDK11 and store the jar file in an MS SQL Reporting server. Then I created a job scheduled to run in a specific time inside SQL Server Agent (using CmdExec) from MS SQL Server Management Studio. When the job runs, it will run the batch file e.g. E:\B4JServer\run.bat
B4X:
@ECHO OFF
CD /d E:\Java\jdk-11.0.1\bin
java --module-path E:\Java\jdk-11.0.1\javafx\lib --add-modules ALL-MODULE-PATH -jar "E:\B4JServer\job.jar" 1
* 1 at the end of command is an optional CommandLineArgs to pass to the jar.

The jar file (B4J app) will connect to the MS SQL database (using jdbcSQL) and query a value and then send a push notification using GCM and exit. So, what I have in the production server is 2 folders i.e. E:\Java which stores the extracted jdk-11.0.1 folder and E:\B4JServer to store the job.jar and run.bat files.
 
Top