Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load Java Runtime Environment #144

Closed
gcbartlett opened this issue Oct 5, 2018 · 31 comments
Closed

Unable to load Java Runtime Environment #144

gcbartlett opened this issue Oct 5, 2018 · 31 comments
Labels

Comments

@gcbartlett
Copy link
Contributor

The application (installed either via HomeBrew, or from a direct download/install of DMG) on macOS High Sierra won't start. It displays a dialog with the message "Unable to load Java Runtime Environment".

image

Running the kse.jar with java -jar kse.jar under /Applications/KeyStore Explorer.app/Contents/Java results in:

$ java -jar kse.jar
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/asn1/x500/X500NameStyle
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
	at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
	at java.lang.Class.getMethod0(Class.java:3018)
	at java.lang.Class.getMethod(Class.java:1784)
	at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
	at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.asn1.x500.X500NameStyle
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	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)
	... 7 more

If I look at the MANIFEST.MF file, I see:

Manifest-Version: 1.0
Built-JDK: 9
Implementation-Title: KeyStore Explorer
Implementation-Version: 5.4.0
Implementation-Vendor: Wayne Grant, Kai Kramer
Specification-Title: KeyStore Explorer
Specification-Version: 5.4.0
Specification-Vendor: Wayne Grant, Kai Kramer
Main-Class: org.kse.KSE
Class-Path: lib/darcula.jar lib/bcpkix-jdk15on-1.60.jar lib/jna-4.5.2.
 jar lib/commons-io-2.6.jar lib/javahelp-2.0.05.jar lib/miglayout-swin
 g-5.2.jar lib/jgoodies-looks-2.7.0.jar lib/jgoodies-common-1.8.1.jar
 lib/bcprov-jdk15on-1.60.jar lib/miglayout-core-5.2.jar
Built-Date: 2018-09-19 22:59:49
SplashScreen-Image: org/kse/gui/images/splash.png
Sealed: true

Notice that the Class-Path specifies that the dependencies are in a subdirectory lib, but this doesn't exist in the Java folder:

$ ls -l
total 21032
-rw-r--r--@ 1 garybartlett  admin   796532 Sep 19 13:59 bcpkix-jdk15on-1.60.jar
-rw-r--r--@ 1 garybartlett  admin  4189874 Sep 19 13:59 bcprov-jdk15on-1.60.jar
-rw-r--r--@ 1 garybartlett  admin   214788 Sep 19 13:59 commons-io-2.6.jar
-rw-r--r--@ 1 garybartlett  admin   346471 Sep 19 13:59 darcula.jar
-rw-r--r--@ 1 garybartlett  admin   562749 Sep 19 13:59 javahelp-2.0.05.jar
-rw-r--r--@ 1 garybartlett  admin    37807 Sep 19 13:59 jgoodies-common-1.8.1.jar
-rw-r--r--@ 1 garybartlett  admin   400791 Sep 19 13:59 jgoodies-looks-2.7.0.jar
-rw-r--r--@ 1 garybartlett  admin  1484022 Sep 19 13:59 jna-4.5.2.jar
-rw-r--r--@ 1 garybartlett  admin  2584137 Sep 19 13:59 kse.jar
-rw-r--r--@ 1 garybartlett  admin   106939 Sep 19 13:59 miglayout-core-5.2.jar
-rw-r--r--@ 1 garybartlett  admin    22390 Sep 19 13:59 miglayout-swing-5.2.jar

This same layout and error occurs if I try to build the application and appbundle from source.

As a workaround, I can create a symlink ln -s . lib in this directory and then the app starts when run with java -jar kse.jar, but it still doesn't work when the .app is double-clicked.

Environment

  • Version of KSE: 5.4.0
  • Version of Java: 1.8.0_181 (when running from command line; I have several versions installed via HomeBrew)
  • Platform (OS): macOS 10.13.6
@kaikramer
Copy link
Owner

I have several versions installed via HomeBrew

It might be a problem that the JREs were installed via HomeBrew. I am not sure, if macOS finds those when you click on the .app. I'll have to investigate a bit here...

The layout and manifest file seem wrong, but actually are fine when you run KSE as an app bundle.

Until I have figured out what happens here, you can either download the ZIP package, which includes a shell script (kse.sh) that also works under macOS or you could install a JRE from Oracle.

@gcbartlett
Copy link
Contributor Author

you can either download the ZIP package, which includes a shell script (kse.sh) that also works under macOS or you could install a JRE from Oracle

Thanks Kai. Both of your suggestions worked. Obviously the latter is preferable as it allows use of the application in the normal way. It would still be good, if it didn't have to rely on a component installed by the Oracle installation, though.

@kaikramer
Copy link
Owner

I have tried a newer version of the launcher software that is used to start KSE in the app bundle and it seems to find the Java runtime that was installed via Homebrew. I'll put it in the next release of KSE, but leave this ticket open in case it doesn't fully solve the problem.

@kaikramer kaikramer added this to the v5.4.1 milestone Oct 10, 2018
@kaikramer kaikramer added the bug label Oct 10, 2018
@kaikramer kaikramer removed this from the v5.4.1 milestone Oct 27, 2018
@neetkee
Copy link

neetkee commented Oct 29, 2018

Same error with sdkman java with 5.4.1 version

@kaikramer
Copy link
Owner

@neetkee The problem with sdkman is that it installs the Java runtime under ~/.sdkman and then only modifies the PATH. This works perfectly fine for command line software: Download the ZIP package of KSE and use kse.sh.
For the app bundle however, the Java runtime has to be in one of the standard locations (e.g. /Library/Java/JavaVirtualMachines/jdk-9.jdk) and/or /usr/libexec/java_home should point to it.

@mouse07410
Copy link
Contributor

mouse07410 commented Jan 5, 2019

Does the current version (5.4.1) work with JDK-11.0.1? I seem to have difficulties, like - it would pop the "Add Extensions" window, but when I actually add them, won't accept the "OK" button...

To be more precise - loading from Template seems broken. Extensions in them are not editable. You click on the "pencil" button, and nothing happens. Those same extensions are successfully set when entered without Template. Templates in question were saved by KSE-5.2.1 (or even older), and used successfully with 5.2.1 (don't remember if I used them with later versions, until now).

@kaikramer
Copy link
Owner

@mouse07410 There were inconsistencies in earlier versions of KSE in how extensions were internally stored, which caused some bugs. Those inconsistencies/bugs are fixed, but templates stored with older versions might be incompatible now. I'll look into it, but it's certainly not related to JDK11. Then there is a known (and fixed in git) bug that the "Use Standard Template" button does nothing, which is also unrelated to JDK11.

@kjjaeger
Copy link

kjjaeger commented Feb 6, 2019

I am seeing this on both Amazon Corretto 8 and also AzulSystems Zulu 8 (both certified versions of Java 8). I can see them using /usr/libexec/java_home -V

Matching Java Virtual Machines (2):
1.8.0_202-zulu-8.36.0.1, x86_64: "Zulu 8" /Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home
1.8.0_202, x86_64: "Amazon Corretto 8" /Library/Java/JavaVirtualMachines/amazon-corretto-8.jdk/Contents/Home

When I run Keystore Explorer from the command line by going into KeyStore Explorer.app/Contents/MacOS and running ./"KeyStore Explorer" I get this:

2019-02-05 19:42:05.279 KeyStore Explorer[38823:8385153] NSString *findJavaDylib(NSString , _Bool, _Bool, _Bool, _Bool) Searching for a JRE.
2019-02-05 19:42:05.280 KeyStore Explorer[38823:8385153] NSString findJREDylib(int, _Bool, _Bool) JRE search exception: 'launch path not accessible'
2019-02-05 19:42:05.350 KeyStore Explorer[38823:8385153] NSString findJDKDylib(int, _Bool, _Bool) JDK search exception: '
-[__NSCFString substringFromIndex:]: Index 9223372036854775811 out of bounds; string length 59'
2019-02-05 19:42:05.350 KeyStore Explorer[38823:8385153] NSString *findJavaDylib(NSString *, _Bool, _Bool, _Bool, _Bool) No matching JRE or JDK found.
2019-02-05 19:42:05.350 KeyStore Explorer[38823:8385153] int launch(char *, int, char **) Launchpath: (null)
2019-02-05 19:42:05.354 KeyStore Explorer[38823:8385153] int launch(char *, int, char **) Error launching JVM Runtime ((null)) Relative Path: '(null)' (dylib: (null))
error: Unable to load Java Runtime Environment.

I get this if one or the other or both of Amazon Corretto 8 or Zulu 8 are installed.

@kjjaeger
Copy link

kjjaeger commented Feb 6, 2019

I also tried AdoptOpenJDK jdk8u202-b08 (manually unzipped into /Library/Java/JavaVirtualMachines) Same exact error occurs.

Interestingly AdoptOpenJDK jdk-11.0.2+9 works ok albeit with some warnings:

2019-02-05 20:02:50.498 KeyStore Explorer[41895:8401189] NSString *findJavaDylib(NSString *, _Bool, _Bool, _Bool, _Bool) Searching for a JRE.
2019-02-05 20:02:50.499 KeyStore Explorer[41895:8401189] NSString *findJREDylib(int, _Bool, _Bool) JRE search exception: 'launch path not accessible'
2019-02-05 20:02:50.568 KeyStore Explorer[41895:8401189] int launch(char *, int, char **) Launchpath: /Library/Java/JavaVirtualMachines/jdk-11.0.2+9/Contents/Home/lib/jli/libjli.dylib
2019-02-05 20:02:50.577 KeyStore Explorer[41895:8401198] NSString *findJavaDylib(NSString *, _Bool, _Bool, _Bool, _Bool) Searching for a JRE.
2019-02-05 20:02:50.577 KeyStore Explorer[41895:8401198] NSString *findJREDylib(int, _Bool, _Bool) JRE search exception: 'launch path not accessible'
2019-02-05 20:02:50.642 KeyStore Explorer[41895:8401198] int launch(char *, int, char **) Launchpath: /Library/Java/JavaVirtualMachines/jdk-11.0.2+9/Contents/Home/lib/jli/libjli.dylib
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.kse.gui.MacOsIntegration (file:/Users/jaegerk/Applications/KeyStore%20Explorer.app/Contents/Java/kse.jar) to constructor com.apple.eawt.Application()
WARNING: Please consider reporting this to the maintainers of org.kse.gui.MacOsIntegration
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

@kaikramer
Copy link
Owner

@kjjaeger I am aware of the problems with the alternative Java distributions and I am working on solutions.

@kjjaeger
Copy link

kjjaeger commented Feb 7, 2019

@kaikramer Good to know. I will stick with Oracle JDK 8 for a while longer.

@childnode
Copy link

same here for OpenJDK 12

-bash:/Applications/KeyStore Explorer.app/Contents/Java
-bash:$ java -classpath ./ -jar kse.jar 
Error: Unable to initialize main class org.kse.KSE
Caused by: java.lang.NoClassDefFoundError: org/bouncycastle/asn1/x500/X500NameStyle

-bash:/Applications/KeyStore Explorer.app/Contents/Java
-bash:$ /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/openjdk-12.jdk/Contents/Home

@kaikramer
Copy link
Owner

@childnode Please read my comments above. You can't run the jar file from the application bundle with java -jar unless you add all dependencies to the classpath. If you want to run KSE from the command line then you have to download the ZIP package.

KSE works fine with OpenJDK 12, it's just that the native launcher in the app bundle doesn't find the JRE.

@jeffplesko
Copy link

jeffplesko commented Jun 10, 2019

I am having the same problem still. Regardless of how I install java, the KSE launcher will not find the JRE. Java is installed:

java -version
java version "12.0.1" 2019-04-16
Java(TM) SE Runtime Environment (build 12.0.1+12)
Java HotSpot(TM) 64-Bit Server VM (build 12.0.1+12, mixed mode, sharing)

Is there not any option that can be explicitly added to the plist file to point at the java install?

@kaikramer
Copy link
Owner

Just a quick status update: A pull request for appbundler (the KSE launcher for macOS) that adds support for newer and alternative Java distributions is in testing:
https://bitbucket.org/infinitekind/appbundler/pull-requests/55/extend-refactoring-to-iterate-over/diff

@gedankennebel
Copy link

I have the same issue after DMG install, but starting kse via the kse.sh script worked for macOS!

@kjjaeger
Copy link

Just a recent observation:
AdoptOpenJDK HotSpot 11.0.4 for MacOS is somehow able to work with KSE (not sure how)

but these all fail:
AdoptOpenJDK HotSpot 12.0.2
Zulu 11.33.15 (aka 11.0.4)
Zulu 12.3.11 (aka 12.0.2)

@pitometsyurii
Copy link

See the same issue on any java version.

@kjjaeger
Copy link

I have found a workaround for Azul Systems Zulu 8 and 11 on MacOS. Zulu 8 or 11 get installed into /Library/Java/JavaVirtualMachines as zulu-8.jdk or zulu-11.jdk. Rename the package to something with 'jdk' in the name BEFORE the extension, like zulujdk-8.jdk or zulujdk-11.jdk . Launching using the icon seems to work for me by doing this rename. This doesn't seem to work for Zulu 12 (and AdoptOpenJDK 12 fails as well). I believe the issue there is related to libjli.dylib being moved up a directory from JDK 12 onward.

@kjjaeger
Copy link

kjjaeger commented Aug 1, 2019

It looks like the issue has been addressed upstream in AppBundler for a couple months now. https://bitbucket.org/infinitekind/appbundler/pull-requests/55/extend-refactoring-to-iterate-over/diff Could a new 5.4.x release be made that includes the new fixed AppBundler? Thanks.

@sandeepdixit05
Copy link

sandeepdixit05 commented Aug 3, 2019

Hi Kai, I have installed the JRE 12 from Oracle on my Mac.
https://www.oracle.com/technetwork/java/javase/downloads/jdk12-downloads-5295953.html

But I face the same issue. "Unable to load Java Runtime Environment".

@ghost
Copy link

ghost commented Aug 10, 2019

I was able to run it by using the .zip file with the kse.sh script on a Mac

@kaikramer
Copy link
Owner

KSE 5.4.2 released

@mshahat
Copy link

mshahat commented Feb 7, 2020

unable to load java runtime envrionment. this is with keystore explorer app, installed through brew cask.

my java both 1.8 and 1.11 are installed using sdkman.

Cheers

@kaikramer
Copy link
Owner

@mshahat See my comment above: #144 (comment)

@FranklinYu
Copy link

@mshahat we are using appbundler to find the Java runtime. If you want it to support sdkman then you can create an issue there. For example, I had issue opening it with Java from MacPorts, and I created TheInfiniteKind/appbundler#59.

@dennisrichter
Copy link

I did a test on my Mac with Catalina 10.15.3. I have Amazons Corretto JDK 11 and 8 installed. JAVA_HOME is set correctly and yet KSE 5.4.3 seems to be broken. It just can't find my Java runtime. I uninstalled 5.4.3 and re-installed 5.4.2 and this one works.
This is my workaround: using 5.4.2 because the Java detection in 5.4.3. seems to have an issue.

@vkolotov
Copy link

Same thing for me on my mac. 5.4.2 works fine, 5.4.3 does not work.

@ruslanf
Copy link

ruslanf commented Mar 16, 2020

Under Catalina on my Mac 5.4.3 does not work

@woj-tek
Copy link

woj-tek commented Jul 21, 2020

Just a quick question - why not just use JAVA_HOME to get desired java installation? It's the most universal thing out there.

I just wanted to check one keystore with KSE 5.4.3 and got the same error. KSE from brew, OracleJDK8_u202, AdoptOpenJDK (build 11.0.8+10)

EDIT: Bundle from the website works just fine so only brew version seems to be affected.

@kaikramer
Copy link
Owner

@woj-tek How would you set JAVA_HOME? In ~/.profile, ~/.bashrc, ~/.zshrc or something similar? All of these locations only work for command line applications. Those files are evaluated when you open the terminal. GUI applications just don't see those environment variables.

There is a way to make environment variables available for GUI applications (see https://apple.stackexchange.com/a/106814/356482) but this is not for the average user.

Furthermore the macOS launcher is a third party component, I cannot simply change how it works. I have considered writing my own launcher, but that wouldn't change the messy situation with different Java distributions and take more of my time dealing with OS specific problems instead of working on actual KSE features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests