B4J Question Error when running JAR

Discussion in 'B4J Questions' started by aeric, Jun 13, 2019.

  1. aeric

    aeric 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
    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.
     
  2. sorex

    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
     
  3. aeric

    aeric Active Member Licensed User

    Code:
    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;
     
  4. sorex

    sorex Expert Licensed User

    is your B4J paths pointed to a 1.8.0_211 JDK? or that alternative one
     
    Last edited: Jun 13, 2019
  5. aeric

    aeric Active 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
     
  6. sorex

    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
     
  7. aeric

    aeric Active Member Licensed User

    Code:
    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)
     
  8. aeric

    aeric Active Member Licensed User

    This cause :
    Code:
    Error: could not open `c:\Program Files (x86)\Java\jre1.8.0_211\lib\jvm.cfg'
     
  9. sorex

    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
     
  10. aeric

    aeric Active Member Licensed User

    I use another command to run
    Code:
    java --module-path C:\Java\jdk-11.0.1\javafx\lib --add-modules ALL-MODULE-PATH -jar "C:\Development\Job\Objects\job.jar"
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    Tips:
    1. class file version 53.0 = Java 9+.
    2. If you are using Java 11 then your best option to distribute a UI app is with B4JPackager11.
     
  12. aeric

    aeric Active Member Licensed User

    Thanks. I have converted my app to non-UI version. My problem resolved. I use the openjdk 11.
     
  13. Didier9

    Didier9 Active 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)
     
  14. aeric

    aeric Active Member Licensed User

    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
    Code:
    @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.
     
    Didier9 likes this.
  15. Erel

    Erel Administrator Staff Member Licensed User

    This is expected. Executable jars will not work with Java 11 (for UI apps).

    B4JPackager11 should work. If you encountered any issue then start a new thread and post the information.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice