Eclipse tomcat java.lang.ClassNotFoundException: com.web.servlets.SearchServiceServlet - java

Tomcat throws exception
java.lang.ClassNotFoundException: com.web.servlets.SearchServiceServlet every time i try to access my servlet.
The servlets is in the correct package structure:
I defined my servlet in the web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
<display-name>PetClinic</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<session-config>
<session-timeout>15</session-timeout>
</session-config>
<servlet>
<servlet-name>searchService</servlet-name>
<servlet-class>com.web.servlets.SearchServiceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>searchService</servlet-name>
<url-pattern>/searchServ</url-pattern>
</servlet-mapping>
</web-app>
The servlet class:
public class SearchServiceServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* #see HttpServlet#HttpServlet()
*/
public SearchServiceServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String first_name = request.getParameter("first_name");
String last_name = request.getParameter("last_name");
int age = Integer.valueOf( request.getParameter("age") );
String pet_name = request.getParameter("pet_Name");
String pet_type = request.getParameter("pet_type");
int rating = Integer.valueOf(request.getParameter("rating"));
int experience = Integer.valueOf(request.getParameter("experience"));
System.out.println("First name = "+first_name+",last name = "+last_name+",age = "+age+",pet's name = "+pet_name+",pet's type = "+pet_type+",rating = "+rating+",experience = "+experience);
}
/**
* #see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
Could it be that eclipse doesn't properly generate classes?If yes,how can i test this?Because a simple POJO with main method works fine.
Also,here is the full exception and what the tomcat prints when i start the application:
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version name: Apache Tomcat/9.0.17
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Mar 13 2019 15:55:27 UTC
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version number: 9.0.17.0
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Windows 10
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 10.0
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: amd64
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: C:\Program Files\Java\jdk1.8.0_181\jre
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.8.0_181-b13
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: C:\Users\Barracuda\Desktop\Projects\Eclipse Projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: C:\Program Files\Apache Software Foundation\Tomcat 9.0
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=C:\Users\Barracuda\Desktop\Projects\Eclipse Projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 9.0
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=C:\Users\Barracuda\Desktop\Projects\Eclipse Projects\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=C:\Program Files\Apache Software Foundation\Tomcat 9.0\endorsed
апр 11, 2019 12:15:21 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1251
апр 11, 2019 12:15:21 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: An older version [1.2.17] of the APR based Apache Tomcat Native library is installed, while Tomcat recommends a minimum version of [1.2.21]
апр 11, 2019 12:15:21 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: Loaded APR based Apache Tomcat Native library [1.2.17] using APR version [1.6.3].
апр 11, 2019 12:15:21 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
апр 11, 2019 12:15:21 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
апр 11, 2019 12:15:22 PM org.apache.catalina.core.AprLifecycleListener initializeSSL
INFO: OpenSSL successfully initialized [OpenSSL 1.0.2o 27 Mar 2018]
апр 11, 2019 12:15:22 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
апр 11, 2019 12:15:23 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
апр 11, 2019 12:15:23 PM org.apache.catalina.startup.Catalina load
INFO: Server initialization in [2 666] milliseconds
апр 11, 2019 12:15:23 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Catalina]
апр 11, 2019 12:15:23 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet engine: [Apache Tomcat/9.0.17]
апр 11, 2019 12:15:23 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
апр 11, 2019 12:15:24 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
апр 11, 2019 12:15:24 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
апр 11, 2019 12:15:24 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
апр 11, 2019 12:15:24 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in [987] milliseconds
апр 11, 2019 12:15:28 PM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet [searchService] as unavailable
апр 11, 2019 12:15:28 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet [searchService]
java.lang.ClassNotFoundException: com.web.servlets.SearchServiceServlet
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1363)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1186)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:540)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:521)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:150)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1031)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:761)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:134)
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.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
P.S The class is in the right package :package com.web.servlets;

Try specifying the package in your class file.
package com.web.servlets;

java.lang.ClassNotFoundException Exception is thrown when the ClassLoader cannot find the specified class.
You have:
<servlet-class>com.web.servlets.SearchServiceServlet</servlet-class>
That means you have a package: com.web.servlets where the class SearchServiceServlet is located.
In case you have a Maven project you should have scr/main/java/%yourpackagename%/yourClass
In case it is a simple web-project then it should be like src/yourpackagename/yourClass.

The problem got fixed after the restart of eclipse...Though there is another problem. Whenever i save the servlets class,after changing it,it doesn't see the new class,but uses the previous version of it.What's the problem here?

Related

Error running project on tomcat in eclipse

I have a test listener which i created for learning purposes. It was working fine and i was trying to learn JSTL and added the dependent jar to build path and also pasted them under WEB-INF/lib directory of my project, i also did a maven update because my JSTL was not working. Now when i try to run tomcat and access through browser i get below error
Below is my project directory and tomcat logs from console.
Console logs:
Feb 23, 2022 11:53:38 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version name: Apache Tomcat/8.5.69
Feb 23, 2022 11:53:38 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Jun 30 2021 18:00:00 UTC
Feb 23, 2022 11:53:38 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version number: 8.5.69.0
Feb 23, 2022 11:53:38 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Windows 10
Feb 23, 2022 11:53:38 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 10.0
Feb 23, 2022 11:53:38 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: amd64
Feb 23, 2022 11:53:38 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: C:\Users\shiva\.p2\pool\plugins\org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_16.0.2.v20210721-1149\jre
Feb 23, 2022 11:53:38 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 16.0.2+7-67
Feb 23, 2022 11:53:38 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
Feb 23, 2022 11:53:38 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: C:\Users\shiva\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Feb 23, 2022 11:53:38 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: D:\Software\apache-tomcat-8.5.69-windows-x64\apache-tomcat-8.5.69
Feb 23, 2022 11:53:38 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=C:\Users\shiva\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Feb 23, 2022 11:53:38 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=D:\Software\apache-tomcat-8.5.69-windows-x64\apache-tomcat-8.5.69
Feb 23, 2022 11:53:38 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=C:\Users\shiva\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
Feb 23, 2022 11:53:38 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: --add-opens=java.base/java.lang=ALL-UNNAMED
Feb 23, 2022 11:53:38 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: --add-opens=java.base/java.io=ALL-UNNAMED
Feb 23, 2022 11:53:38 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: --add-opens=java.base/java.util=ALL-UNNAMED
Feb 23, 2022 11:53:38 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: --add-opens=java.base/java.util.concurrent=ALL-UNNAMED
Feb 23, 2022 11:53:38 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
Feb 23, 2022 11:53:38 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1252
Feb 23, 2022 11:53:38 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -XX:+ShowCodeDetailsInExceptionMessages
Feb 23, 2022 11:53:38 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path: [C:\Users\shiva\.p2\pool\plugins\org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_16.0.2.v20210721-1149\jre\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Users/shiva/.p2/pool/plugins/org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_16.0.2.v20210721-1149/jre/bin/server;C:/Users/shiva/.p2/pool/plugins/org.eclipse.justj.openjdk.hotspot.jre.full.win32.x86_64_16.0.2.v20210721-1149/jre/bin;C:\app\shiva\product\21c\dbhomeXE\bin;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Program Files (x86)\dotnet\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;D:\Software\mongosh-1.1.7-win32-x64\mongosh-1.1.7-win32-x64\bin;C:\Users\shiva\AppData\Local\Microsoft\WindowsApps;C:\Users\shiva\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\shiva\AppData\Roaming\npm;C:\apache-maven-3.8.2\bin;C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.3\bin;;D:\Software\mongosh-1.1.7-win32-x64\mongosh-1.1.7-win32-x64\bin;;C:\Users\shiva\Desktop;;.]
Feb 23, 2022 11:53:38 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Feb 23, 2022 11:53:38 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Feb 23, 2022 11:53:38 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 974 ms
Feb 23, 2022 11:53:38 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Catalina]
Feb 23, 2022 11:53:38 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet engine: [Apache Tomcat/8.5.69]
Feb 23, 2022 11:53:39 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Error configuring application listener of class [shop.MyServletContextListener]
java.lang.ClassNotFoundException: shop.MyServletContextListener
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1415)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1223)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:538)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:519)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:150)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4686)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5232)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1429)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at java.base/java.lang.Thread.run(Thread.java:831)
Feb 23, 2022 11:53:39 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Skipped installing application listeners due to previous error(s)
Feb 23, 2022 11:53:39 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file
Feb 23, 2022 11:53:39 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/shop] startup failed due to previous errors
Feb 23, 2022 11:53:39 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Feb 23, 2022 11:53:39 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 487 ms
Below is my web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="WebApp_ID" version="3.1">
<display-name>Shopping Application</display-name>
<servlet>
<servlet-name>shoppingServlet</servlet-name>
<servlet-class>shop.ShoppingServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>shoppingServlet</servlet-name>
<url-pattern>/shopping</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>loginServlet</servlet-name>
<servlet-class>shop.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>loginServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>downloadServlet</servlet-name>
<servlet-class>shop.DownloadServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>downloadServlet</servlet-name>
<url-pattern>/down</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>listenerServlet</servlet-name>
<servlet-class>shop.ListenerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>listenerServlet</servlet-name>
<url-pattern>/listen</url-pattern>
</servlet-mapping>
<context-param>
<param-name>breed</param-name>
<param-value>German Shephard</param-value>
</context-param>
<servlet>
<servlet-name>MyTest</servlet-name>
<jsp-file>/MyTest.jsp</jsp-file>
<init-param>
<param-name>email</param-name>
<param-value>shivamsingh794#gmail.com</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>MyTest</servlet-name>
<url-pattern>/MyTest.jsp</url-pattern>
</servlet-mapping>
<listener>
<listener-class>
shop.MyServletContextListener
</listener-class>
</listener>
</web-app>

ServletContainerInitializer Not Working

package sampleJSN;
import java.io.IOException;
import java.util.Set;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Init implements ServletContainerInitializer {
#SuppressWarnings("serial")
#Override
public void onStartup(Set<Class<?>> arg0, ServletContext arg1) throws ServletException {
System.out.println("ssd");
HttpServlet serv = new HttpServlet() {
#Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.getWriter().write("<b>JSN</b>");
}
#Override
public void init(ServletConfig config) throws ServletException {
System.out.println("sirappu");
super.init(config);
}
};
Dynamic dyc = arg1.addServlet("Name", serv);
dyc.addMapping("/jsn");
}
}
I was writing a programme to test ServletContainerInitializer.the problem is ServletContainerInitializer itself works properly and ServletContainerInitializer.onStartup is called "ssd" is printed however the ServletContext.addServlet does not register my servlet and hence init method is not called. please check the log bellow
Apr 11, 2018 12:18:45 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:CheckWeb' did not find a matching property.
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/8.0.36
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Jun 9 2016 13:55:50 UTC
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number: 8.0.36.0
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Windows 8.1
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 6.3
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: amd64
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: C:\Program Files\Java\jdk1.8.0_161\jre
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.8.0_161-b12
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: C:\Users\BalajiGold\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: C:\tomcat-8
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:63748
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=C:\Users\BalajiGold\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\tomcat-8
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=C:\Users\BalajiGold\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=C:\tomcat-8\endorsed
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1252
Apr 11, 2018 12:18:45 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.8.0_161\jre\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\Java\jdk1.8.0_161\jre\bin;C:/Program Files/Java/jdk1.8.0_121/jre/bin/server;C:/Program Files/Java/jdk1.8.0_121/jre/bin;C:/Program Files/Java/jdk1.8.0_121/jre/lib/amd64;C:\Program Files\Microsoft MPI\Bin\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\system32;C:\Windows;C:\Program Files\QuickTime\QTSystem;C:\cygwin64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\MinGW\bin;C:\MinGW\MSYS\1.0\bin;C:\Program Files\Git\bin;C:\Users\BalajiGold\AppData\Local\Programs\Eclipse Che\eclipse-che-5.0.0\tools\jre\bin;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files\Microsoft SQL Server\140\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\;C:\Program Files\Java\jdk1.8.0_161\bin;C:\Program Files\Docker Toolbox;C:\apache-maven-3.5.2\bin;C:\Users\BalajiGold\Desktop;;.
Apr 11, 2018 12:18:45 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Apr 11, 2018 12:18:45 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Apr 11, 2018 12:18:45 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Apr 11, 2018 12:18:45 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Apr 11, 2018 12:18:45 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 941 ms
Apr 11, 2018 12:18:45 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Apr 11, 2018 12:18:45 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.36
Apr 11, 2018 12:18:48 AM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Apr 11, 2018 12:18:50 AM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
ssd
Apr 11, 2018 12:18:54 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Apr 11, 2018 12:18:54 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Apr 11, 2018 12:18:54 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 9179 ms
dyc.setLoadOnStartup(0);
this code solved the above problem for me
PS: Don't forget to add META-INF/services/javax.servlet.ServletContainerInitializer

JAX-RS on TomCat always returns 404

I have already looked at many tutorials, but I can't get my simple JAX-RS application to work. Tomcat always returns Error 404.
The Application to get Classes:
package api;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
#ApplicationPath("/resources")
public class MyApplication extends Application {
// All request scoped resources and providers
#Override
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<>();
classes.add(AuthenticationEndpoint.class);
return classes;
}
}
My JAX-RS file:
package api;
#Path("/hello")
public class AuthenticationEndpoint {
#GET
public Response getUser() {
return Response.status(200).entity("getUser is called").build();
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>MSM-Master</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>MyApplication</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>api</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MyApplication</servlet-name>
<url-pattern>/resources</url-pattern>
</servlet-mapping>
</web-app>
Under "Web Project Settings" my Context root is: "MSM-Master"
The url I tried to call was:
http://localhost:8080/MSM-Master/resources/hello/
Edit:
added Tomcat Console output:
Dez 14, 2017 4:32:39 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNUNG: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:MSM-Master' did not find a matching property.
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Server version: Apache Tomcat/8.0.30
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Server built: Dec 1 2015 22:30:46 UTC
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Server number: 8.0.30.0
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: OS Name: Windows 7
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: OS Version: 6.1
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Architecture: amd64
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Java Home: C:\Program Files\Java\jre1.8.0_66
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: JVM Version: 1.8.0_66-b18
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: JVM Vendor: Oracle Corporation
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: CATALINA_BASE: C:\Users\u016975\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: CATALINA_HOME: C:\Program Files\Apache Software Foundation\Tomcat 8.0
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dcatalina.base=C:\Users\u016975\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 8.0
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dwtp.deploy=C:\Users\u016975\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Djava.endorsed.dirs=C:\Program Files\Apache Software Foundation\Tomcat 8.0\endorsed
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dfile.encoding=Cp1252
Dez 14, 2017 4:32:39 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFORMATION: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre1.8.0_66\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;C:/Program Files/Java/jre1.8.0_66/bin/server;C:/Program Files/Java/jre1.8.0_66/bin;C:/Program Files/Java/jre1.8.0_66/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Java\jdk1.8.0_66\bin;C:\Program Files\Git\cmd;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Users\u016975\AppData\Roaming\npm\;C:\Users\u016975\apache-ant-1.9.7\bin;C:\Users\u016975\AppData\Local\Android\android-sdk\tools;C:\Users\u016975\AppData\Local\Android\android-sdk\platform-tools;C:\windows\system32; C:\windows; C:\windows\System32\Wbem;C:\Applications\Atlassian\atlassian-plugin-sdk-6.2.14\bin;C:\Users\u016975\AppData\Local\Apps\cURL\bin;C:\Applications\Atlassian\atlassian-plugin-sdk-6.2.15\bin;node_modules\npm;C:\Program Files\nodejs\;C:\Users\u016975\apache-ant-1.9.7\bin;C:\Users\u016975\AppData\Local\Android\android-sdk\tools;C:\Users\u016975\AppData\Local\Android\android-sdk\platform-tools;C:\windows\system32; C:\windows; C:\windows\System32\Wbem;C:\Applications\Atlassian\atlassian-plugin-sdk-6.2.14\bin;C:\Users\u016975\AppData\Local\Apps\cURL\bin;C:\Applications\Atlassian\atlassian-plugin-sdk-6.2.15\bin;node_modules\npm;C:\Users\u016975\AppData\Roaming\npm;C:\Program Files\Microsoft VS Code\bin;C:\Users\u016975\Downloads\eclipse-jee-mars-1-win32-x86_64\eclipse;;.
Dez 14, 2017 4:32:39 PM org.apache.coyote.AbstractProtocol init
INFORMATION: Initializing ProtocolHandler ["http-nio-8080"]
Dez 14, 2017 4:32:39 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMATION: Using a shared selector for servlet write/read
Dez 14, 2017 4:32:39 PM org.apache.coyote.AbstractProtocol init
INFORMATION: Initializing ProtocolHandler ["ajp-nio-8009"]
Dez 14, 2017 4:32:39 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMATION: Using a shared selector for servlet write/read
Dez 14, 2017 4:32:39 PM org.apache.catalina.startup.Catalina load
INFORMATION: Initialization processed in 621 ms
Dez 14, 2017 4:32:39 PM org.apache.catalina.core.StandardService startInternal
INFORMATION: Starting service Catalina
Dez 14, 2017 4:32:39 PM org.apache.catalina.core.StandardEngine startInternal
INFORMATION: Starting Servlet Engine: Apache Tomcat/8.0.30
Dez 14, 2017 4:32:46 PM org.apache.jasper.servlet.TldScanner scanJars
INFORMATION: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Dez 14, 2017 4:32:46 PM org.apache.catalina.core.StandardContext startInternal
SCHWERWIEGEND: Error during ServletContainerInitializer processing
javax.servlet.ServletException: java.lang.InstantiationException: org.glassfish.tyrus.server.TyrusServerConfiguration
at org.apache.tomcat.websocket.server.WsSci.onStartup(WsSci.java:88)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5244)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.InstantiationException: org.glassfish.tyrus.server.TyrusServerConfiguration
at java.lang.Class.newInstance(Unknown Source)
at org.apache.tomcat.websocket.server.WsSci.onStartup(WsSci.java:74)
... 8 more
Caused by: java.lang.NoSuchMethodException: org.glassfish.tyrus.server.TyrusServerConfiguration.<init>()
at java.lang.Class.getConstructor0(Unknown Source)
... 10 more
Dez 14, 2017 4:32:46 PM org.apache.catalina.core.StandardContext startInternal
SCHWERWIEGEND: Context [/MSM-Master] startup failed due to previous errors
Dez 14, 2017 4:32:46 PM org.apache.coyote.AbstractProtocol start
INFORMATION: Starting ProtocolHandler ["http-nio-8080"]
Dez 14, 2017 4:32:46 PM org.apache.coyote.AbstractProtocol start
INFORMATION: Starting ProtocolHandler ["ajp-nio-8009"]
Dez 14, 2017 4:32:46 PM org.apache.catalina.startup.Catalina start
INFORMATION: Server startup in 6457 ms
#ApplicationPath provided by JAX – RS which is used to develop a restful web services application with out web.xml. So you can delete your web.xml
Then try overriding getProperties
#ApplicationPath("/resources")
public class MyApplication extends Application {
// All request scoped resources and providers
#Override
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<>();
classes.add(AuthenticationEndpoint.class);
return classes;
}
#Override
public Map<String, Object> getProperties() {
final Map<String, Object> properties = new HashMap<>();
properties.put("jersey.config.server.provider.packages",
"api");//api-->here mention your yourpackage.to.scan"
return properties;
}
}

Logback ClassCircularityError

I changed from Windows to Ubuntu 17.04 and now I get an Error when I start the webapp on a Tomcat 8.0.36 via Eclipse Neon.3 Release (4.6.3).
java.lang.ClassCircularityError: ch/qos/logback/core/spi/FilterReply
The project is build via M2E has AspectJ in it.
Uses following SLF4J Dependencies:
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.7</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.21</version>
</dependency>
It work's under Windows Eclipse with almost same settings and installation.
Also it works when I mvn clean package (default ubuntu maven installation not eclipse one) and deployed it manually to the default Tomcat installation of Ubuntu.
I already changed my eclipse version to Oxygen and got the same problem.
I tried to change the versions of the dependencies too - same result.
I have debuged the code to a "ServletContextListener" that tries to get a JDNI object:
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.slf4j.LoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.classic.jul.LevelChangePropagator;
import ch.qos.logback.core.util.StatusPrinter;
// ....
#Override
public void contextInitialized(final ServletContextEvent sce) {
new LogRecord(Level.FINEST, "Ensure class is loaded!");
// Prepare logging context
final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
context.reset();
// setup JUL to SLF4J log bridging
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
final LevelChangePropagator levelChangePropagator = new LevelChangePropagator();
levelChangePropagator.setResetJUL(true);
levelChangePropagator.setContext(context);
levelChangePropagator.start();
context.addListener(levelChangePropagator);
// Load context values
String contextPath = sce.getServletContext().getContextPath().replaceAll("[^0-9a-zA-Z-_]", "");
if(contextPath.length() == 0){
contextPath = "ROOT";
}
context.putProperty("appName", contextPath);
final Boolean isProductiveVal = (Boolean) getJNDI(IS_PRODUCTIVE_JNDI);
// .....
private static Object getJNDI(final String jndiPath) {
try {
final Context initialContext = new InitialContext(); // << This line crashes
return initialContext.lookup(jndiPath);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
I have no clue what I could try to fix it. And also im not fully understand the problem. Tomcat tries to load a Class that reference it self?!
Does some one have a clue what I could check?
Full stack of Tomcat start.
Sep 06, 2017 5:05:36 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNUNG: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:MyProject' did not find a matching property.
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Server version: Apache Tomcat/8.0.36
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Server built: Jun 9 2016 13:55:50 UTC
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Server number: 8.0.36.0
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: OS Name: Linux
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: OS Version: 4.10.0-33-generic
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Architecture: amd64
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Java Home: /usr/lib/jvm/java-8-openjdk-amd64/jre
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: JVM Version: 1.8.0_131-8u131-b11-2ubuntu1.17.04.3-b11
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: JVM Vendor: Oracle Corporation
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: CATALINA_BASE: /home/kani/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: CATALINA_HOME: /opt/tomcat8
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:37177
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Drebel.base=/home/kani/.jrebel
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Drebel.env.ide.plugin.version=7.0.14
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Drebel.env.ide.version=4.6.3
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Drebel.env.ide.product=Eclipse
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Drebel.env.ide=eclipse
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Drebel.notification.url=http://localhost:17434
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Drebel.workspace.path=/home/kani/eclipse-workspace
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Drebel.properties=/home/kani/.jrebel/jrebel.properties
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -agentpath:/opt/eclipse/plugins/org.zeroturnaround.eclipse.embedder_7.0.14.RELEASE/jrebel/lib/libjrebel64.so
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dcatalina.base=/home/kani/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dcatalina.home=/opt/tomcat8
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dwtp.deploy=/home/kani/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Djava.endorsed.dirs=/opt/tomcat8/endorsed
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMATION: Command line argument: -Dfile.encoding=UTF-8
Sep 06, 2017 5:05:36 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFORMATION: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib
Sep 06, 2017 5:05:36 PM org.apache.coyote.AbstractProtocol init
INFORMATION: Initializing ProtocolHandler ["http-nio-8080"]
Sep 06, 2017 5:05:36 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMATION: Using a shared selector for servlet write/read
Sep 06, 2017 5:05:36 PM org.apache.coyote.AbstractProtocol init
INFORMATION: Initializing ProtocolHandler ["ajp-nio-8009"]
Sep 06, 2017 5:05:36 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMATION: Using a shared selector for servlet write/read
Sep 06, 2017 5:05:36 PM org.apache.catalina.startup.Catalina load
INFORMATION: Initialization processed in 802 ms
Sep 06, 2017 5:05:36 PM org.apache.catalina.core.StandardService startInternal
INFORMATION: Starting service Catalina
Sep 06, 2017 5:05:36 PM org.apache.catalina.core.StandardEngine startInternal
INFORMATION: Starting Servlet Engine: Apache Tomcat/8.0.36
2017-09-06 17:05:37 JRebel: Directory '/home/kani/eclipse-workspace/MyProject/target/classes' will be monitored for changes.
2017-09-06 17:05:37 JRebel: Directory '/home/kani/eclipse-workspace/MyProject/target/m2e-wtp/web-resources' will be monitored for changes.
2017-09-06 17:05:37 JRebel: Directory '/home/kani/eclipse-workspace/MyProject/src/main/webapp' will be monitored for changes.
Sep 06, 2017 5:05:41 PM org.apache.jasper.servlet.TldScanner scanJars
INFORMATION: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Sep 06, 2017 5:05:41 PM org.apache.catalina.core.ApplicationContext log
INFORMATION: No Spring WebApplicationInitializer types detected on classpath
java.lang.ClassCircularityError: ch/qos/logback/core/spi/FilterReply
at ch.qos.logback.classic.LoggerContext.getTurboFilterChainDecision_0_3OrMore(LoggerContext.java:267)
at ch.qos.logback.classic.Logger.filterAndLog_0_Or3Plus(Logger.java:373)
at ch.qos.logback.classic.Logger.log(Logger.java:765)
at org.slf4j.bridge.SLF4JBridgeHandler.callLocationAwareLogger(SLF4JBridgeHandler.java:221)
at org.slf4j.bridge.SLF4JBridgeHandler.publish(SLF4JBridgeHandler.java:303)
at java.util.logging.Logger.log(Logger.java:738)
at java.util.logging.Logger.doLog(Logger.java:765)
at java.util.logging.Logger.logp(Logger.java:931)
at org.apache.juli.logging.DirectJDKLog.log(DirectJDKLog.java:180)
at org.apache.juli.logging.DirectJDKLog.debug(DirectJDKLog.java:103)
at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:361)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
at org.apache.catalina.startup.Catalina.start(Catalina.java:629)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.__invoke(DelegatingMethodAccessorImpl.java:43)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)
I changed to the Tomcat8 installation that I used in windows.
And it finally worked (I didn't know what the previous Head of did there).
The only difference I can see instantly is that it used Log4j also on Tomcat side. Maybe thats the difference. Sorry if someone else also have this problem and no solution.

Error instantiating servlet class com.XYZClass

When I try to load servlet in my eclipse neon, it gives me "Error instantiating servlet class com.Test" error stating that "The server encountered an internal error that prevented it from fulfilling this request." I can load .jsp page successfully but while trying to load servlet page it gives me following error in eclipse borwser.
and console generates following error.
Sep 07, 2016 9:03:01 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Demo' did not find a matching property.
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/7.0.70
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Jun 15 2016 16:27:45 UTC
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number: 7.0.70.0
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Windows 7
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 6.1
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: amd64
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: C:\Program Files\Java\jre1.8.0_101
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.8.0_101-b13
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: D:\darshana\eWorkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: C:\Program Files\Apache Software Foundation\Tomcat 7.0
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=D:\darshana\eWorkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 7.0
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=D:\darshana\eWorkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp2\wtpwebapps
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=C:\Program Files\Apache Software Foundation\Tomcat 7.0\endorsed
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1252
Sep 07, 2016 9:03:01 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre1.8.0_101\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_101/bin/server;C:/Program Files/Java/jre1.8.0_101/bin;C:/Program Files/Java/jre1.8.0_101/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\PuTTY\;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\nodejs\;C:\Program Files\MongoDB\Server\3.2\bin;C:\Users\darshana.ahalpara\AppData\Roaming\npm;C:\Program Files\MongoDB\Server\3.2\bin;C:\Program Files\Java\jdk1.8.0_101\bin;;C:\Users\darshana.ahalpara\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Eclipse;;.
Sep 07, 2016 9:03:01 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8085"]
Sep 07, 2016 9:03:01 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Sep 07, 2016 9:03:01 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 731 ms
Sep 07, 2016 9:03:02 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Sep 07, 2016 9:03:02 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.70
Sep 07, 2016 9:03:02 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8085"]
Sep 07, 2016 9:03:02 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Sep 07, 2016 9:03:02 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 954 ms
Sep 07, 2016 9:03:27 AM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet Demo as unavailable
Sep 07, 2016 9:03:27 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet Demo
java.lang.ClassNotFoundException: com.Test
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1891)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1734)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:504)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:486)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:113)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1146)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:866)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:134)
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:169)
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:442)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Following is my directory structure.
here my Test.java
package com.abc;
import java.io.IOException;
import javax.servlet.ServletException;
//import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class Test
*/
//#WebServlet("/Test")
public class Test extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* #see HttpServlet#HttpServlet()
*/
public Test() {
super();
// TODO Auto-generated constructor stub
}
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Hello....!!!!!! ");//.append(request.getContextPath());
}
}
Here is web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>Demo</servlet-name>
<servlet-class>com.abc.Test</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Demo</servlet-name>
<url-pattern>/demo</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>example</servlet-name>
<jsp-file>/exmpl.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>example</servlet-name>
<url-pattern>/example</url-pattern>
</servlet-mapping>
</web-app>

Categories

Resources