JNI error: Exception in thread "main" java.lang.NoClassDefFoundError - java

Error log:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/text/StrSubstitutor
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.apache.commons.text.StrSubstitutor
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 7 more
I know that people have asked this question before but none of them are using the Dropwizard framework.
Here is what I have tried:
Different versions of Dropwizard using the pom.xml,
Adding commons-lang and commons-text don't seem to fix it, though commons-text makes it throw a different error,
Restarting my computer.
It is a pretty involved pom.xml file which I am not comfortable sharing...
Any ideas why this is happening?

Is it possible, that you compile with a newer version (like Java 8) and run it with an older version (Java 7)? If yes, check the Path. (1)
Another thing could be, that the apache libraries are compiled with a more recent version.
(1) Try comparing the output of java --version and javac --version

Related

NoClassDefFoundError using jars

I am new to Java and trying around. Now I would like to learn about network - server client communications. Long story short I found jars on github which should make the start easier. So I downloaded the file and added it to my Modulepath. Everything looked OK while writing a simple start to just connect but when I want to run for testing I get the NoClassDefFoundError ...
Exception in thread "main" java.lang.NoClassDefFoundError: com/blogspot/debukkitsblog/net/Server
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1010)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:855)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:753)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:676)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:634)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
at fst.serverclient.ssc.SSCNetzwerkTester.main(SSCNetzwerkTester.java:6)
Caused by: java.lang.ClassNotFoundException: com.blogspot.debukkitsblog.net.Server
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
... 10 more
I do not have any idea what am I doing wrong, the jar should work otherwise it should not be there for download I guess. But the error comes from one of the jar classes called Server:
java.lang.NoClassDefFoundError: com/blogspot/debukkitsblog/net/Server

Java cannot find javax/vecmath/Vector3d.class, even with jar in classpath

My platform has ubuntu 18.04.3 and openjdk version "1.8.0_242".
I'm running someone's executable jar file which references javax.vecmath.Vector3d, but the the openjdk vm generates NoClassDefFoundError for that class, as displayed below. The javax class is installed on my system in /usr/share/java/vecmath.jar, I've verified that it contains javax.vecmath.Vector3d, so I provide that jar in the '-cp' option:
% java -cp /usr/share/java/vecmath.jar -jar cameraCalc.jar
But I get this error:
java -cp /usr/share/java/vecmath-1.5.2.jar -jar cameraCalc.jar
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: [Ljavax/vecmath/Vector3d;
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: javax.vecmath.Vector3d
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
... 7 more
Why can't the jvm find that class even though it's in the vecmath.jar provided as a '-cp' option?
Thanks
Tom
My problem was due to running an executable jar file that does not contain all needed classes. From the documentation:
When you use this option, the JAR file is the source of all user
classes, and other user class path settings are ignored.
So "-cp" options will be ignored when running an executable jar file.

Compiled JAVA project, can't make it work

got a problem, can't manage it to work for me right.
Completed my java project and i want it to compile and run for a test. I do compile it as "Jar file" (not runnable jar file). I compile it through Eclipse IDE.
I do not setup any more references in compiling settings, making everything stock. Once i compile it as "Server.jar" in my desktop i'm trying to run through console, because it's more like console program. I'm using macOS.
Using command : java -jar Server.jar
Error:
Ervinass-MacBook-Air:Desktop Ervinas$ java -jar Server.jar
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/simple/parser/ParseException
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.json.simple.parser.ParseException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
What should i do?
It shouws class is not found if i'm right?
This : org/json/simple/parser/ParseException is not recognised.
What i have tried : java -classpath ~/Documents/Java/Server/src/server/json-simple.jar -jar Server.jar
As all of you see, i'm using json-simple.jar library, moreover i do use mysql library, so i guess later it will be the same problem with mysql library.
Any solution? Tired of getting it working now..

DSC Signing on Linux server by ePass 2003 token

I am trying to sign an XML using ePass 2003 token on Linux machine.
Signing is successful in Windows machine but it threw an exception in Linux machine.
The exception is given below:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/cms/CMSException
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.cms.CMSException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Configuration of Linux machine is listed below
Java : JDK 1.8 update 91
Token : ePass 2003
PKCS11_KEYSTORE_TYPE = "PKCS11";
DIGITAL_SIGNATURE_ALGORITHM_NAME ="SHA256withRSA";
SUN_PKCS11_PROVIDER_CLASS = "sun.security.pkcs11.SunPKCS11";
DLL_PATH = "/home/ePass2003-Linux-x64/redist/libcastle.so.1.0.0";
Please help me.
It is running well on Window machine, but throwing listed .
It is error due to incorrect path of folder.
It not a measure issue.
Please check basic java flow of code.
Some silly mistakes has been done!!

java.lang.NoClassDefFoundError: org/apache/spark/sql/SchemaRDD

I am getting a NoClassDefFound error when trying to run Spark. I cannot figure out the reason behind this. Please help.
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/spark/sql/SchemaRDD
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 org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:659)
at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:180)
at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:205)
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:120)
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
Caused by: java.lang.ClassNotFoundException: org.apache.spark.sql.SchemaRDD
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 10 more
NoClassDefFoundError means Java couldn't find the Class it was looking for. That normally means:
You defined wrongly the classpath.
Java is finding and using the wrong version of the jar (probably because of Maven dependency hell).
Solution for 1 is to check the classpath: make sure you are including the jar that defines org.apache.spark.sql.SchemaRDD.
Solution for 2 is to check if you have a Maven dependency that depends (transitively) on an older version of the resource that defines that class.

Categories