How to reference .jars in web.xml? - java

I first came across the following error in Tomcat7 log:
SEVERE: Servlet.service() for servlet [XYZ] in context with path [] threw exception
I learned that I am potentially missing 3rd party .jars so I added them to my project in NetBeans (right click Project > Properties > Libraries > Add JAR). I rebuilt the WAR file and deployed the project again in Tomcat7 server. But I am still getting similar errors.
Then I came across this question where someone suggests configuring the .jars in web.xml, which leads me to my main question: How do I reference 3rd party .jars in my web.xml?
The full error log is below. Any help/guidance is appreciated. Thank you.
SEVERE: Servlet.service() for servlet [XYZ] in context with path [] threw exception
java.lang.NullPointerException
at com.xyz.data.ConnectPool.getConnection(ConnectPool.java:42)
at com.xyz.data.xyzDB.getXYZ(xyzDB.java:23)
at com.xyz.servlets.XYZServlet.processRequest(XYZServlet.java:42)
at com.xyz.servlets.XYZServlet.doGet(XYZServlet.java:67)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

Related

NoClassDefFoundError but class exist after deployment of WAR file

I have a servlet based application and it works, when I run it from within Eclipse. I've created a WAR file and deployed it to Tomcat. After deployment I find the unpacked files of my WAR project in webapps/ directory.
But when I try open the servlet, via url, I get the following error:
exception
javax.servlet.ServletException: Servlet execution threw an exception
root cause
java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.tesseract$TessBaseAPI
com.gorcer.iseeyou.FounderMgr.prepareEnv(FounderMgr.java:80)
com.gorcer.iseeyou.Api.doGet(Api.java:54)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.56 (Debian) logs.
Full stack:
май 19, 2016 5:52:03 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [ApiServlet] in context with path [] threw exception [Servlet execution threw an exception] with root cause
java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.tesseract$TessBaseAPI
at com.gorcer.iseeyou.FounderMgr.prepareEnv(FounderMgr.java:80)
at com.gorcer.iseeyou.Api.doGet(Api.java:54)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
I looked at WEB-INF/lib and found "tesseract-3.04-1.1.jar". It contains the missing class named "tesseract$TessBaseAPI.class".
Why isn't it included?

ClassNotFoundException in servlet project

I am getting ClassNotFoundException for the class oracle.jdbc.driver.OracleDriver that is present in the ojbc14.jar file. I have found some answer for this question but non of the solution worked.
My project structure is below.
some suggested to added the ojdbc14.jar file by
right click on project -> build path --> CONFIGURE BUILD PATH --> add external jar . I have done that but still getting the error in the server window in eclipse.
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1854)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1703)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:259)
at com.ars.util.DBConnection.getCon(DBConnection.java:20)
at com.ars.dao.UserLoginDAO.checkUserLoginDetails(UserLoginDAO.java:18)
at com.ars.handler.UserLoginHandler.doPost(UserLoginHandler.java:53)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)
at com.ars.controller.ARSController.doPost(ARSController.java:110)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
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)
when I open the ojdbc14.jar file from the package explorer. I get the below path.
how to resolve the issue can anyone please help.
Libraries (like the ojdbc14.jar) need to be placed into the directory WEB-INF/lib inside your WAR. The provided screenshot shows that you placed your library into the directory WEB-INF (note the missing lib).
Alternatively, you can place libraries that might be shared among several web applicatons into the directory <tomcat>/lib. This is the preferred way for JDBC driver libraries.
Open your war (or directory that you are deploying), and check if this file is present in WEB-INF/lib directory. If not, you have to add it there.
Second solution would be to put it inside your application server lib directory. For example {tomcatHomeDir}/lib. Second approatch has one advantage: your application will have smaller (thinner) war file. On the other hand deploying multiple applications on same server, that are using different oracle libraries can be troublesone.

Axis2 web services not generated [?wsdl]

I am experiencing a problem querying wsdl for Axis2 web service.
We have list of web services published through Axis2 on Tomcat web server.
When i query using URL,
http://HostName:/xyz/services/myservice?wsdl
it throws "Internal Server error" and found following error in Tomcat log.
org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [AxisServlet] in context with path [/xyz] threw exception
java.lang.NullPointerException
at org.apache.axis2.transport.http.AxisServlet.getEPRsForService(AxisServlet.java:579)
at org.apache.axis2.description.AxisService.calculateEPRs(AxisService.java:981)
at org.apache.axis2.description.AxisService.calculateEPRs(AxisService.java:931)
at org.apache.axis2.description.AxisService.getEPRs(AxisService.java:924)
at org.apache.axis2.description.AxisService.setPortAddress(AxisService.java:1386)
at org.apache.axis2.description.AxisService.printDefinitionObject(AxisService.java:1009)
at org.apache.axis2.description.AxisService.printUserWSDL(AxisService.java:1030)
at org.apache.axis2.description.AxisService.printWSDL(AxisService.java:1306)
at org.apache.axis2.transport.http.ListingAgent.processListService(ListingAgent.java:270)
at org.apache.axis2.transport.http.AxisServlet.doGet(AxisServlet.java:249)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
I learnt that on ?wsdl as a part of URL, Axis generates WSDL file dynamically. but I couldn't find which component/configuration/library is responsible not working correctly and how this problem can be fixed.
Appreciate your help.

Where to place a Jar file when using Tomcat

I am developing an server application using Tomcat and Java EE eclipse.
Since I need to handle the Json, I use the org.json.jar and in eclipse I add it as an external Jar files, so that my codes can be compiled.
But when I run the server and handle the Post request, an error occurs as follows:
SEVERE: Servlet.service() for servlet [servlets.SimpleServlet] in context with path [/MateServer] threw exception [Servlet execution threw an exception] with root cause
java.lang.NoClassDefFoundError: org/json/JSONObject
at servlets.SimpleServlet.doPost(SimpleServlet.java:56)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
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)
Then where should I place the org.json.jar file?

how to import a .JAR file in the "/dist" folder of a Java Application project in netbeans to eclipse

i have a spring mvc project in eclipe spring tools suite IDE and i wanted to add some classes from a WSDL, i try using maven-jaxb2-plugin but it dont do nothing when i update my project using maven. So i try to create a web service client in eclipse and in the service definition i put my WSDL url but after a few seconds loading it gives me a Invalid segment definition, after all this i try creating a Java Application Project in Netbeans and then add a web services client in that project with my WSDL url this time it worked!, so i try to add the .JAR file of that project that locates in D:/Users/myUser/Documents/NetBeansProjects/ImportClassesFromWSDL/dist/ImportClassesFromWSDL.jar
i added this jar as a external JAR following this steps How to import a jar in Eclipse , the .JAR was added but i have this warning
Classpath entry D:/Users/myUser/Documents/NetBeansProjects/ImportClassesFromWSDL/dist/ImportClassesFromWSDL.jar will not be exported or published. Runtime ClassNotFoundExceptions may result. WSproject P/WSproject Classpath Dependency Validator Message
in the eclipse text editor i can write with no problems the name of the classes and create objects of this classes with no problem, but at the moment when i run my project and get to the part when i create this objects from the imported classes i get a class not found exception
HTTP 500 - Handler processing failed; nested exception is java.lang.NoClassDefFoundError: mycompany/myws/myschema/myClassWs
: Servlet.service() servlet [appServlet] [/app] [Handler processing failed; nested exception is java.lang.NoClassDefFoundError: mycompany/myws/myschema/myClassWs] java.lang.ClassNotFoundException: mycompany/myws/myschema/myClassWs
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at com.pruebaWsCompany.app.HomeController.myWsPage(HomeController.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I got this to work, I copied the .jar to my WEB-INF/lib directory.
Thanks for #Arkantos who suggested it.

Categories