I am trying to build a login-registration web app which essentially lets users register on a database and then allows them to log in. I have written all the code, and I am trying to connect my program to my database. Here is the error I receive:
Exception
javax.servlet.ServletException: Servlet execution threw an exception
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause
java.lang.NoClassDefFoundError: java/sql/Driver
I have added all the Postgres, Tomcat, and SQL connector/driver jar to my classpath and my WEB-INF/lib folders. I am not really sure what else to do. I have tried testing with another class and I am able to connect to my database. I have triple check my connection URL as well. What's wrong?
Thanks!
I know this has nothing to do with Servlets, but I had the same problem with a module application that uses SQLite:
Exception in thread "main" java.lang.NoClassDefFoundError: java/sql/Driver
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1095)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:206)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:759)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassInModuleOrNull(BuiltinClassLoader.java:680)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:605)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:315)
...
Caused by: java.lang.ClassNotFoundException: java.sql.Driver
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 14 more
A little puzzling at at first, but I finally figured it out. I just had to add the requires statement for java.sql to the module-info.java:
module mymodule {
...
requires sqlite.jdbc;
requires java.sql;
}
(The requires sqlite.jdbc was already in there, added it above just for clarity)
If you are getting this problem while running Jetpack compose desktop app,
consider adding this line into build.gradle.kts
compose.desktop {
application {
// ..
nativeDistributions {
// ...
modules("java.sql")
}
}
}
Related
Good day,
I am new to Talend, I am trying to create a Schema for tFileInputDelimited component. The Schema is trying to read a text file from a folder.
However, during step 3 on creating this Schema, I am hitting some class not found exception:
Exception in thread "main" java.lang.NoClassDefFoundError: com/talend/csv/CSVWriter
at orion_dl_track.shadowfileinputtodelimitedoutput_0_1.ShadowFileInputToDelimitedOutput.tFileInputDelimitedProcess(ShadowFileInputToDelimitedOutput.java:1709)
at orion_dl_track.shadowfileinputtodelimitedoutput_0_1.ShadowFileInputToDelimitedOutput.runJobInTOS(ShadowFileInputToDelimitedOutput.java:2436)
at orion_dl_track.shadowfileinputtodelimitedoutput_0_1.ShadowFileInputToDelimitedOutput.main(ShadowFileInputToDelimitedOutput.java:2295)
Caused by: java.lang.ClassNotFoundException: com.talend.csv.CSVWriter
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 3 more
Preview error. Some settings must be changed.
Note: Preview errors are generally due to a wrong encoding setting.
org.talend.designer.runprocess.shadow.ShadowFilePreview.preview(ShadowFilePreview.java:90)
org.talend.metadata.managment.ui.utils.ShadowProcessHelper.getCsvArray(ShadowProcessHelper.java:383)
org.talend.repository.ui.wizards.metadata.connection.files.delimited.DelimitedFileStep2Form$PreviewProcessor.nonUIProcessInThread(DelimitedFileStep2Form.java:1309)
org.talend.commons.ui.swt.thread.SWTUIThreadProcessor$1.run(SWTUIThreadProcessor.java:74)
For java program, then I will know I need to import this library into my project, like adding the gradle implementation script from Maven website.
But how about this talend? Is it I need to go some where to download the jar and import into Talend Studio?
OS: Ubuntu 22.04.1 LTS
java: openjdk-18.0.2.1
I got the folowing error when trying to connect to a MongoDB database from ReactiveMongo API (reactivemongo_3-1.1.0-noshaded-RC6):
java.lang.NoClassDefFoundError: reactivemongo/core/errors/ConnectionException
Exception in thread "main" java.lang.NoClassDefFoundError: reactivemongo/core/errors/ConnectionException
at reactivemongo.api.AsyncDriver$.apply(AsyncDriver.scala:503)
at e2m.MongoExport.<init>(MongoExport.scala:35)
at e2m.MongoExport$.<clinit>(MongoExport.scala:82)
at e2m.MongoExport.main(MongoExport.scala)
Caused by: java.lang.ClassNotFoundException: reactivemongo.core.errors.ConnectionException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 4 more
I looked for the package "reactivemongo.core.errors" inside the jar file and I did not found it.
Could you help me out by telling me which jar file should I include in my project to solve this problem?
Thanks
Everything works fine when debugging the project on the intelij environment.
But when I try to execute
java -jar myJar.jar
I get
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/support/ui/Wait
at com.anyclip.App.main(App.java:43)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.support.ui.Wait
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 1 more
I tried several solutions, including this one (ClassNotFoundException on a Maven Project using Selenium), but all failed.
How can I overcome this?
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
Typically I start by Googling for a solution, but this error does not seem to have occurred before.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/util/Shell
at org.apache.hadoop.hive.conf.HiveConf$ConfVars.findHadoopBinary(HiveConf.java:906)
at org.apache.hadoop.hive.conf.HiveConf$ConfVars.<clinit>(HiveConf.java:237)
at org.apache.hive.jdbc.HiveConnection.isHttpTransportMode(HiveConnection.java:221)
at org.apache.hive.jdbc.HiveConnection.openTransport(HiveConnection.java:138)
at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:123)
at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at com.merck.ghh.ingestion.HiveTableSetup.tableSetup(HiveTableSetup.java:31)
at com.merck.ghh.ingestion.HiveTableSetup.main(HiveTableSetup.java:546)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.util.Shell
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 10 more
The following code causes this error, specifically on the Connection declaration line:
try {
Class.forName(driverName);
Connection connection = DriverManager.getConnection("jdbc:hive2://localhost:10000/default", "hive", "");
Statement statement = connection.createStatement();
} catch (ClassNotFoundException exception) {
exception.printStackTrace();
}
Other questions seem to point to this being related to not including hadoop-core in the dependencies, but hadoop-core does not seem to exist in the Hadoop 2.X. I am specifically working in Hadoop 2.1.0.2.0.5.0-67 with Hive 0.12.0. Before this error I was having issues bc my Hive dependencies had gotten destroyed at some point, but I put those back in and this error happened next. I'm wondering if it's not something as simple as forgetting a dependency, but I'm not finding which dependency I might be missing.
Any help with this is greatly appreciated.
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.util.Shell
As you are using Hadoop 2.X. you need to download hadoop-common-2.1.0-beta.jar OR
hadoop-common-2.0.0-cdh4.4.0.jar and to class path to avoid ClassNotFoundException.
You are right earlier hadoop-core-0.20.2-737.jar was used.
For more visit http://grepcode.com/
Try copying the JDBC connector jar into the $HIVE_HOME/lib/ folder. I faced a similar issue and copying the jar file worked for me.