1

Throughout my application I want to add the username and password to database when a user registers and clicks on "sign up" through servlet2.java but on local tomcat deployment instead of adding data to database class not found exception is thrown, I have already added mysql jar to lib but still no benefit. Here is the downloadable link to my project. If anybody can please help correcting the issue.

Here is the full stack trace.

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1363)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1186)
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:315)
    at source.servlet2.database(servlet2.java:23)
    at source.servlet2.doPost(servlet2.java:16)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.base/java.lang.Thread.run(Thread.java:834)
22-May-2019 19:22:52.550 INFO [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [D:\apache-tomcat-9.0.17\webapps\manager]
22-May-2019 19:22:52.735 INFO [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [D:\apache-tomcat-9.0.17\webapps\manager] has finished in [185] ms
Syntle
  • 5,168
  • 3
  • 13
  • 34
fuzious
  • 400
  • 5
  • 19
  • Can you please add the stack trace as well. – Deepak Sharma May 22 '19 at 07:56
  • 1
    Also, please check if the jars are present in the lib directory inside the application directory under tomcat/webapps/. – Deepak Sharma May 22 '19 at 07:57
  • we need a lot more to help. Full stacktrace, the way you added the driver, maven? Manual in IDE? what is the jar you added etc. – maslan May 22 '19 at 08:05
  • You can add the to tomcat classpath jar as described here https://stackoverflow.com/a/7198049/2000323 – Andrey May 22 '19 at 09:20
  • Well I have added the stack trace , I added the jar through project structure/modules/library/maven and then downloaded the latest version of mysql jar – fuzious May 22 '19 at 13:57

1 Answers1

4

You have the provided scope for the jdbc driver jar. In this cases it is not copied into the artifact that you deploy to tomcat. You need to specify it as a compile scope. enter image description here

You can also add the to tomcat classpath jar as described here https://stackoverflow.com/a/7198049/2000323 for all applications. Then you must specify the scope as provided so that the same jar would not be deployed twice.

Andrey
  • 15,144
  • 25
  • 91
  • 187
  • I have added all the 4 war files to tomcat /lib but and marked the scope as provided and tried by both marking and unmarking the export option but still facing the issue,i have added the stack trace as well – fuzious May 22 '19 at 14:10