Using JNI so files on a dynamic web project(Apache Tomcat Server) - java

I am making a dynamic web project, which requires to use an external jar file. That jar uses several JNI so files. Now I have the jar and all the required so files. I have added the jar to the java build path, but I am not sure how to introduce the so files to the tomcat server.
I tried adding path to the so file as "LD_LIBRARY_PATH":
(Properties->Run/Debug Settings->edit->Environment->Select) and also
adding the path to "java.library.path"(Run
As->RunConfigurations->Tomcat v8 Server->Arguments->VM arguments)
flag.
Still it is not working, I am getting below error, whenever the my code is trying to access functions/classes from the above mentioned jar:
SEVERE: Servlet.service() for servlet [org.iotivity.simulator.agent.LaunchSimulator] in context with path
[/SimulatorAgent] threw exception [Servlet execution threw an
exception] with root cause java.lang.ClassNotFoundException:
org.oic.simulator.server.SimulatorResource$Type at
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1305)
at
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1139)
at
org.iotivity.simulator.agent.LaunchSimulator.doPost(LaunchSimulator.java:86)
at
org.iotivity.simulator.agent.LaunchSimulator.doGet(LaunchSimulator.java:45)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1502)
at
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1458)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
I have tried the same code with a simple Java Application, and it works fine by setting the LD_LIBRARY_PATH variable.
Any suggestion will be highly appreciated.

Your error is a ClassNotFoundException, which would suggest that the JAR isn't properly included. If there was a problem with the native library, you'd get a UnsatisfiedLinkError instead. To make the JAR available to Tomcat, you'd need to add it to the classpath (-classpath=/path/to/your.jar) or include it in your WAR. The latter depends on your build system, but if you use Maven it's rather easy using the maven-shade-plugin (this only works for the JAR though, the native code you'll have to keep on distributing separately). Hope that helps!

Related

Tomcat server not working anymore after a stop and restart

I've got an error related to tomcat server. I shut down my server (took a while) and then when a start the server back, an error appears :
org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [com.amadeus.security.CCDVAccess#2a9cce4a] with key 'CCDVAccess'; nested exception is javax.management.InstanceAlreadyExistsException: com.amadeus.security:name=CCDVAccess
org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:625)
org.springframework.jmx.export.MBeanExporter.registerBeans(MBeanExporter.java:550)
org.springframework.jmx.export.MBeanExporter.afterSingletonsInstantiated(MBeanExporter.java:432)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:795)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
javax.servlet.GenericServlet.init(GenericServlet.java:158)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:632)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110)
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)
org.apache.tomcat.util.net.Nio2Endpoint$SocketProcessor.doRun(Nio2Endpoint.java:1627)
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
org.apache.tomcat.util.net.AbstractEndpoint.processSocket(AbstractEndpoint.java:830)
org.apache.tomcat.util.net.Nio2Endpoint$Nio2SocketWrapper$4.completed(Nio2Endpoint.java:639)
org.apache.tomcat.util.net.Nio2Endpoint$Nio2SocketWrapper$4.completed(Nio2Endpoint.java:617)
org.apache.tomcat.util.net.SecureNio2Channel$1.completed(SecureNio2Channel.java:873)
org.apache.tomcat.util.net.SecureNio2Channel$1.completed(SecureNio2Channel.java:806)
sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:126)
sun.nio.ch.Invoker$2.run(Invoker.java:218)
sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
I know that the error is not related to the code, because nothing change.
I try
to stop and restart many times,
to change the version of the WAR I was using.
to delete the logs and the folder work/catalina
I do not know what else I should try, so I hope some of you has I idea about that. I really think the issue is coming from tomcat but I'm not sure.
Thank for your help
Sébastien
Edit: I solved my issue it was a stupid mistake. I did a backup of my WAR file without changing the extension... Therefore tomcat was launching 2 identicals servers.
Thanks guys for your help
it seems you have two Spring Boot apps in the same JVM so you need to segregate the MBean namespace.
the first log error tell you that.
org.springframework.jmx.export.UnableToRegisterMBeanException: Unable
to register MBean [com.amadeus.security.CCDVAccess#2a9cce4a] with key
'CCDVAccess'; nested exception is
javax.management.InstanceAlreadyExistsException:
com.amadeus.security:name=CCDVAccess
for further clarification
https://github.com/spring-cloud/spring-cloud-config/issues/118.

Exception when forwarding request to servlet in Java web application

I have a problem and I don't know how to solve it.
My web application MyApp is a Maven web application project (Java 8 and Java EE 5). To run an updated version as test instance on the same server, I changed the Context Path of the application from MyApp to MyAppTest. As servlet container, I'm using Tomcat 8.
The MyApp instance is working as expected. However the MyAppTest instance is throwing an exception when forwarding the request to one of my servlets. Even if MyApp and MyAppTest are identical except the context path, this exception occurs. The Servlets are mapped via Guice's ServletModule.
Message:
java.lang.StringIndexOutOfBoundsException: String index out of range: -4
StackTrace:
java.lang.String.substring(Unknown Source)
com.google.inject.servlet.ServletDefinition$2.getPathInfo(ServletDefinition.java:212)
org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:376)
org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318)
myapp.base.MainEntryServlet.service(MainEntryServlet.java:49)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
com.google.inject.servlet.ServletDefinition.doServiceImpl(ServletDefinition.java:286)
com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:276)
com.google.inject.servlet.ManagedServletPipeline$1.doServiceImpl(ManagedServletPipeline.java:154)
com.google.inject.servlet.ManagedServletPipeline$1.forward(ManagedServletPipeline.java:140)
myapp.auth.LogoutServlet.service(LogoutServlet.java:57)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
com.google.inject.servlet.ServletDefinition.doServiceImpl(ServletDefinition.java:286)
com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:276)
com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:181)
com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:91)
com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:85)
com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:120)
com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:135)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
org.apache.coyote.ajp.AbstractAjpProcessor.process(AbstractAjpProcessor.java:873)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)
The Servlet forwarding the Request does this:
RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp");
if (!response.isCommitted()) {
dispatcher.forward(request, response);
}
The URL index.jsp is mapped to another Servlet. It forwards the request to a JSP:
request.getRequestDispatcher("/theme/index.jsp").forward(request, response);
There the exception occurs. Some other JSPs are included into the index.jsp like this:
<jsp:include flush="true" page="menu.jsp"/>
The menu.jsp is located in the same folder as the index.jsp.
As mentioned before, everything works fine as long as the Context path is MyApp. When changed to MyAppTest the exception occurs. It must have something to do with the Context path itself. When changing the Path to MyAppTest, the exception message is "String index out of range: -4". When I change the Path to MyAppTesting, the exception message changes to "String index out of range: -7".
To solve this I tried the following:
Changing the Context path and the docBase to MyAppTest in the context.xml of the project.
Changing the Artifact ID of the project to MyAppTest.
Changing the Project Name to MyAppTest.
Nothing worked. And I don't know what causes the exeption: Maven, Tomcat or Guice.

Running Hbase with Java Servlets

I wrote a Hbase Java basic code that works fine with Java.
public class HBaseTest {
public static String newFunc() throws IOException {
// Instantiating configuration class
Configuration config = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(config);
Table table = connection.getTable(TableName.valueOf("customer"));
Get g = new Get(Bytes.toBytes("jsmith"));
Result result = table.get(g);
// Reading values from Result class object
byte[] value = result.getValue(Bytes.toBytes("addr"), Bytes.toBytes("city"));
return Bytes.toString(value);
}
}
So I decided to use this code and Hbase as a part of my web application development and so I opened a new Dynamic Web Project in Eclipse Java EE IDE and added this file, changed the name of function and called it from one of the servlets. I also added the required jar files.
But I am stuck with the following error:
java.lang.ClassNotFoundException: org.apache.hadoop.hbase.HBaseConfiguration
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1332)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1166)
at HBaseTest.newFunc(HBaseTest.java:18)
at BakwasServlet.doGet(BakwasServlet.java:16)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
This error is frustrating me now. Has anyone encountered such a case before or can anyone help me on this? I don't have hbase_home variable set up. I didn't need it for the java code as well.
Thanks in advance!
Where have you added the HBase JAR file? It should be in the WEB-INF/lib folder of your web application (or in the server's lib folder, but it's better to keep it within the app).

can't change or add action in struts2

i am having a problem with struts i've been working with struts with more than 4 month now
the problem is when i add a new action i get this:
the previous actions work fine but when i modify the name of the action in struts.xml i get the error i mention above.
so for example i have the following code in struts.xml
<action name="test1" class="com.onda.beans.AfficheVolList">
<result name="success">table_vols_test_css.jsp</result>
<result name="fail">admin.jsp</result>
</action>
when i enter http://localhost:8080/Myproject/test1 it works fine
but after i change the name of the action
<action name="test2" class="com.onda.beans.AfficheVolList">
<result name="success">table_vols_test_css.jsp</result>
<result name="fail">admin.jsp</result>
</action>
and i try to enter localhost:8080/Myproject/test2
i got the error in the previous image it doesn't even take me to admin.jsp
i tried to clean the server and clean work directory but nothing work i even changed the server it works for the first time but after i change the name of the action it doesn't work
here is the log
`Jun 01, 2016 12:24:58 PM org.apache.struts2.dispatcher.Dispatcher error
SEVERE: Could not find action or result
/Onda_vol/vols2
There is no Action mapped for namespace [/] and action name [vols2] associated with context path [/Onda_vol]. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:554)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)`
thank you for taking time to answer my question i really appreciate it
This is probably a problem in your Apache Tomcat server configuration.
Your struts.xml looks perfectly fine and there is no reason changing the name would break the action.
Here's a few things you could consider doing and that might solve your problem:
Restart Tomcat
Depending on your linux distro and Tomcat version, this might differ.
sudo service tomcat7 restart
Restart your computer
Delete and reinstall Tomcat
I hope this helps.

MySql Driver Class Autoloading

Configuration
jdk version : 1.8.0_60-b27
project : maven jsp project
Mysql connector : mysql-connector-java-5.1.38 (Copied to Tomcat's lib)
Pom.xml
<!--MySql Connector/J Dependency-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
<scope>provided</scope>
</dependency>
Code Causing Error :
try(Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/myDatabase","root","")){
connection=con;
} catch (SQLException e) {
e.printStackTrace();
return null;
}
Error log
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/myDatabase
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at util.DBConnectivity.getDBConnection(DBConnectivity.java:16)
at controller.MyController.doGet(MyController.java:25)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2503)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2492)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
I tried both of the scopes [provided and compile] in pom.xml but no change in the output!!!
Tried hundred times but can't figure out why project is not able to find the driver????
What you need to do is just these two steps, and not more:
Include your dependency properly:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
Notice that scope is not configures, so by default it will be compile, which will make it available at runtime too.
The combination of manually copying this file to WEB-INF\lib then redeploy with scope=provided will not work because the folder will get recreated. In case you would like to make this jar available only at runtime, you need to place it to Tomcat\lib.
You need to manually load the driver before you attempt to connect anywhere. Make sure you do this before using DriverManager.
Class.forName("com.mysql.jdbc.Driver");
you are not getting the connection from a datasource hence you are not using the mysql driver in the tomcat lib.
Using DriverManager you need to load the jdbc library yourself using Class.forName("com.mysql.jdbc.Driver").newInstance(); and by removing the provided entry for it in the pom.xml or... use a datasource :)

Categories