webpush-java icon indicating copy to clipboard operation
webpush-java copied to clipboard

Error: A JNI error has occurred, please check your installation and try again

Open prasadlodha opened this issue 7 years ago • 3 comments

Using Java on Ubuntu 16.04: openjdk version "1.8.0_162" OpenJDK Runtime Environment (build 1.8.0_162-8u162-b12-0ubuntu0.16.04.2-b12) OpenJDK Server VM (build 25.162-b12, mixed mode)

Though the build was success but I am getting following error while executing the jar: $java -jar webpush-1.jar generate-key

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException
	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: com.beust.jcommander.ParameterException
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 7 more

Please let me know if I am missing anything.

Thanks.

prasadlodha avatar Apr 24 '18 20:04 prasadlodha

How do you build the .jar? Make sure you run ./gradlew shadowJar instead of ./gradlew assemble. The latter does not package dependencies, which would explain the ClassNotFoundException that you're getting.

martijndwars avatar Apr 25 '18 15:04 martijndwars

But I am building the .jar package using Maven. Have included the required dependencies in pom.xml

Also, if I try to comment the above JCommander part in main file for above error then I still get the same error for BountyCastle and so on.

prasadlodha avatar Apr 27 '18 00:04 prasadlodha

To generate the key pair you should follow the exact instructions. That is, run ./gradlew shadowJar and then java -jar build/libs/web-push-3.1.0-all.jar generate-key. That way the JCommander classes end up in the shadowed JAR and you should not get the NoClassDefFoundError. Alternatively, you can skip this step and generate the key pair at https://web-push-codelab.glitch.me.

Also, if I try to comment the above JCommander part in main file for above error then I still get the same error for BountyCastle and so on.

You can use Maven to embed the web-push library in your project. Just make sure the BouncyCastle JAR ends up on your classpath when you run your application. BouncyCastle's JAR is signed, so if you extract the JAR and put its contents in your project's JAR the signature breaks (this is what Maven does by default when you create a shadow JAR/uber JAR/fat JAR).

martijndwars avatar Apr 27 '18 06:04 martijndwars