Discussions
Categories
- 385.5K All Categories
- 5.1K Data
- 2.5K Big Data Appliance
- 2.5K Data Science
- 453.4K Databases
- 223.2K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 47 Multilingual Engine
- 606 MySQL Community Space
- 486 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.2K ORDS, SODA & JSON in the Database
- 584 SQLcl
- 4K SQL Developer Data Modeler
- 188K SQL & PL/SQL
- 21.5K SQL Developer
- 46 Data Integration
- 46 GoldenGate
- 298.4K Development
- 4 Application Development
- 20 Developer Projects
- 166 Programming Languages
- 295K Development Tools
- 150 DevOps
- 3.1K QA/Testing
- 646.7K Java
- 37 Java Learning Subscription
- 37.1K Database Connectivity
- 201 Java Community Process
- 108 Java 25
- 22.2K Java APIs
- 138.3K Java Development Tools
- 165.4K Java EE (Java Enterprise Edition)
- 22 Java Essentials
- 176 Java 8 Questions
- 86K Java Programming
- 82 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 208 Java User Groups
- 25 JavaScript - Nashorn
- Programs
- 666 LiveLabs
- 41 Workshops
- 10.3K Software
- 6.7K Berkeley DB Family
- 3.6K JHeadstart
- 6K Other Languages
- 2.3K Chinese
- 207 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 474 Portuguese
Can I get failure details when JLI_Launch fails due to a class load failure?

TLDR; Can I use JLI_Launch or JNI_CreateJavaVM to launch a Java Swing app and get diagnostics via some API in case the launch fails (e.g., class load failure)? Can I do this without duplicating much code?
The appbundler project, for launching macOS Java applications, launches an app using JLI_Launch. If the created VM cannot load the main class, say, due to a class loader problem, then the app bundler has no way to notify the user. That's because JLI_Launch eventually calls exit.
I quickly discovered there is actually only one documented API and it does not include JLI_Launch.
In my attempts to use the only documented (i.e., in jni.h) vm creation code, I was able to launch only non-swing applications. I believe this has something to do with event loops and multiple threads.
I downloaded the source for JDK 16 and it includes the source for the code that calls JLI_Launch on macOS. It confirmed the calling of the CRT exit function and it exposed the code that I think I'd have to write to make proper use of JNI_CreateJavaVM for a Swing application.
I believe that I could duplicate most of JLI_Launch and its dependencies. Then prevent it from calling exit so that I can interrogate the created virtual machines and see why they failed. But I do not want to do that because surely someone has anticipated that and the code exists someone. Surely.
Below is a listing of filename and function name involved in this "problem", all arranged in a call stack fashion:
src/java.base/macosx/native/libjli/java_md_macosx.m: apple_main src/java.base/macosx/native/libjli/java_md_macosx.m: MacOSXStartup src/java.base/macosx/native/libjli/java_md_macosx.m: CreateExecutionEnvironment src/java.base/share/native/libjli/java.c: JLI_Launch
The Minimal, Complete, Verifiable example that I have to demonstrate the failing of the documented API when launching a Swing (but probably any toolkit) is attached as test.zip.
When the MCV runs Test2 (console hello world), all is well but when it runs Test1 (mcv swing class), it fails in the FindClass function. In fact, FindClass never returns.
$ gcc -o test.exe -DMACOS -g -I $JAVA_HOME/include -I $JAVA_HOME/include/darwin test.c $ javac Test1.java Test2.java $ ./test.exe Test2 # this is the console hello world app returned ok from dlopen /Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home/../MacOS/libjli.dylib returned ok from dlsym returned ok from JNI_CreateJavaVM returned ok from FindClass(Test2) returned ok from GetStaticMethodID Hello, world. returned ok from CallStaticVoidMethod $ ./test.exe Test1 # this is the swing app returned ok from dlopen /Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home/../MacOS/libjli.dylib returned ok from dlsym returned ok from JNI_CreateJavaVM
At the moment test.exe calls FindClass, it enters a seemingly infinite loop. It partially starts the app but only the part of the app that sets the macOS app menu at the top of the current display. You have to press ^C and then click on the app icon to make it stop.
Proof that JLI_Launch is undocumented in the installed JDK's:
$ find /Library/Java/JavaVirtualMachines -name '*.h' -exec grep JLI_Launch {} \; $ find . /Library/Java/JavaVirtualMachines -name '*.h' -exec grep -l JLI_Launch {} \; ./src/java.base/share/native/launcher/defines.h ./src/java.base/share/native/libjli/java.h ./src/jdk.jpackage/share/native/applauncher/JvmLauncher.h $ find . /Library/Java/JavaVirtualMachines -name java.h ./src/java.base/share/native/libjli/java.h $ find /Library/Java/JavaVirtualMachines -name java.h $
JLI_Launch is documented only in the JDK source.