Jersey app deployment error - rest

I have a simple jersey based REST Web service where i'm trying to do a test GET run..
Using Jersey 2.7 & Servlet 3.0 container, I have tried configuring the application using the jersey doc ( JAX-RS application without an Application subclass
I have defined a resource
#Path("/bolt")
public class SpringRequestResource extends BaseResource {
#GET
#Produces("text/plain")
public String getHello() {
return "Hello World!";
}
And my deployment descriptor web.xml as
<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">
<display-name>Alpha</display-name>
<servlet>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
</servlet>
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/myService/*</url-pattern>
</servlet-mapping>
</web-app>
However, upon throwing a GET request via browser through a url http://myName.xyz.com:6080/[projectName]/myService/bolt
It throws the following exception -
javax.servlet.ServletException: Servlet.init() for servlet javax.ws.rs.core.Application threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:851)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:278)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:745)
root cause
java.lang.IllegalStateException: The resource configuration is not modifiable in this context.
org.glassfish.jersey.server.ResourceConfig$ImmutableState.register(ResourceConfig.java:270)
org.glassfish.jersey.server.ResourceConfig$ImmutableState.register(ResourceConfig.java:218)
org.glassfish.jersey.server.ResourceConfig.register(ResourceConfig.java:448)
org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:309)
org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:168)
org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:358)
javax.servlet.GenericServlet.init(GenericServlet.java:160)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:851)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:278)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:745)
Can't seem to figure out the problem here.

I cannot reproduce the issue with Jersey 2.9. You can try to migrate to Jersey 2.9. If it does not help you can create an new issue in https://java.net/jira/browse/JERSEY as this is probably a bug and not your fault. It would be good if you could attach a simple reproducible test case (simple executable maven project that reproduces the problem).
The workaround would be to use extension of Application class or ResourceConfig to configure the application.

Related

Apache Tomcat 8.0 unable to load servlet class written in Kotlin using Eclipse for Java EE, Mars 2

I am using Eclipse for Java EE, Mars 2. I wrote a servlet application first using Java 8 and Apache Tomcat 8.0.x in this IDE and that runs just fine.
Now, I am trying to port the code to Kotlin. But the Apache Tomcat server, it seems like from the information posted below, is unable to locate and load my class LoginServlet.
I've ported the helper classes and just the one servlet class just now named LoginServlet. I am removing all the rest of the code in this question just to present a bare bones skeleton.
Here is my set up:
package bookyard.server;
// import statements ommitted for brevity
open class LoginServlet : HttpServlet() {
override fun doGet(request : HttpServletRequest, response : HttpServletResponse) {
val msg: String = "HTTP GET method not supported.";
try {
response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg);
} catch (e: IOException) {
e.printStackTrace();
}
}
override fun doPost(request : HttpServletRequest, response : HttpServletResponse) {
this.doPostInternal(request, response);
}
private fun doPostInternal(request: HttpServletRequest, response: HttpServletResponse) {
...
}
}
I first annotated the LoginServlet class with the #WebServlet("/login") annotation but that ran the server just fine but gave me a 404 for the path /login and even for the ServletContext path http://localhost:8080/BookyardServer/.
So, I moved the servlet configuration to the WEB-INF\web.xml file and it now looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>BookyardServer</display-name>
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>bookyard.server.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<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>
</web-app>
My project Build Path includes references to all the libraries my code uses. A snapshot of it is provided here.
In my Project Facets and the Targeted Runtimes, I have a reference to the Apache Tomcat 8.0 runtime.
However, when I Debug As -> Debug on Server, the browser reports the following error:
HTTP Status 500 - Error instantiating servlet class bookyard.server.LoginServlet
message Error instantiating servlet class bookyard.server.LoginServlet
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Error instantiating servlet class
bookyard.server.LoginServlet
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
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)
root cause java.lang.ClassNotFoundException:
bookyard.server.LoginServlet
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1332)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1166)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
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)
I am pretty sure this has something to do with the %CLASSPATH% but I am not sure what. I have set the Apache Tomcat jar files in the class path. Everything else that my code uses is also in the class path.
I am not sure why it isn't able to load my servlet class. Could you please help?
==================================================================
EDIT at 2017/09/04:
Hi friends:
I find a workaround. Maybe it can help you.
(1)Create a Kotlin main class, for example:
fun main(args: Array<String>) {
println("Hello, world!")
}
(2)Right click this main class, and select "Run"=>"Kotlin Application"
This will make the Kotlin plugin compile all the Kotlin source files, and generate class files.
(3)Deploy your web app to the App server, but use the outputed class folder instead of the source folders.
for example, if the "output folder" of your app is "var/classes", you can deploy it to the App Server,
like this, in the WTP setting file [.settings/org.eclipse.wst.common.component] :
<wb-resource deploy-path="/WEB-INF/classes" source-path="/var/classes"/>
also you can set this from the Eclipse "Web Deployment Assembly" dialog:
https://eclipse.org/webtools/releases/3.2.0/NewAndNoteworthy/javaee.php
Now, Eclipse WTP plugin will deploy the "var/classes" folder to the app Server, which include all the class files compiled by the Kotlin plugin
==================================================================
EDIT at 2016/11/17:
Hi friends, I created an issue for this problem:
https://youtrack.jetbrains.com/issue/KT-14838
==================================================================
Looks like your kotlin class is not delpoyed to the Tomcat server.
I have the same problem, and still working on it.
Please read this post:
Can not publish Kotlin class files to Tomcat server
I finally solved this problem,
by adding the following setting into the WTP setting file .settings/org.eclipse.wst.common.component :
<wb-resource deploy-path="/WEB-INF/classes"
source-path="/kotlin_bin"/>
Now the Kotlin class files will be compiled into virtual folder /kotlin_bin, and class files in this folder will be deployed into Tomcat Server.
But I think the Kotlin Eclipse plugin should take care of this problem for developers
But new problem happened.
The class files in the [/kotlin_bin] folder contain only the class and method declaration information, but the implementation code are not generated in these class files.
So, even these class files are deployed into the Tomcat Server, When I try to start the Tomcat Server, these incomplete class files will cause a java.lang.ClassFormatError with the following error message:
Absent Code attribute in method that is not native or abstract in
class file xxxx/xxxx/xxxx
If I run a console app from my project, the kotlin plugin will compile source files and generate class files, then I can copy these class files to the Tomcat Server manually.
But this is very inconvenience because I have to do it over and over again in my development process.

Error instantiating servlet class org.glassfish.jersey.servlet.ServletContainer

Hi Trying to write a simple rest webservice. And following the tutorial below:
http://www.tutorialspoint.com/restful/index.htm
But i am getting
HTTP Status 500 - Error instantiating servlet class org.glassfish.jersey.servlet.ServletContainer
Exception:
<body>
<h1>HTTP Status 500 - Error instantiating servlet class org.glassfish.jersey.servlet.ServletContainer</h1>
<div class="line"></div>
<p>
<b>type</b> Exception report
</p>
<p>
<b>message</b>
<u>Error instantiating servlet class org.glassfish.jersey.servlet.ServletContainer</u>
</p>
<p>
<b>description</b>
<u>The server encountered an internal error that prevented it from fulfilling this request.</u>
</p>
<p>
<b>exception</b>
</p>
<pre>javax.servlet.ServletException: Error instantiating servlet class org.glassfish.jersey.servlet.ServletContainer
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
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)
</pre>
<p>
<b>root cause</b>
</p>
<pre>java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1308)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1142)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
Following is the code (Which is mostly same as the tutorial)
package com.abhi;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
#Path("/UserService")
public class UserService {
UserDao userDao = new UserDao();
#GET
#Path("/users")
#Produces(MediaType.APPLICATION_XML)
public List<User> getUsers(){
return userDao.getAllUsers();
}
}
My Web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>MyRestPrjct</display-name>
<servlet>
<servlet-name>Jersey RESTful Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.abhi</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Jersey RESTful Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<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>
</web-app>
I was just not placing the jars in proper way. Instead of placing the required jar in webapps\MyRestPrjct\WEB-INF\lib, I was placing it in webapps\MyRestPrjct\WEB-INF\lib\libs.
It is working fine after I the moved the jars from libs to lib.
Placing all the jars in WEB-INF/lib folder resolved the issue for me.
i too faced similar issue when i did the same tutorial, the problem i found out was the servelt class specified in the web.xml is
org.glassfish.jersey.servlet.ServletContainer
but when i checked in the jars there is no package in the libraries with the above path so i change it to the existing one
com.sun.jersey.spi.container.servlet.ServletContainer
and it solved the issue.
I too got the same exception when trying to run the same module from tutorialspoint. All I did is to download the below jars and added to project. It worked fine.
jersey-common-2.0-m03.jar
jersey-server-2.0-m03.jar
jersey-container-servlet-core-2.28.jar
In my case worked by adding maven dependencies in deployment assembly.(For Maven Project*)
Right click project name (in eclipse) > configure build path > Deployment Assembly (in Left bar) > Add > java build Path Entries > Maven Dependencies > Finish

exception java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer

I just made my first REST api based on this http://www.vogella.com/articles/REST/article.html
I am using eclipse kepler, tomcat7, and Jersey
when I try to "Run on server" I get this error:
SEVERE: Servlet /de.vogella.jersey.first threw load() exception
java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:527)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:509)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:137)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5176)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
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)
Here is the source code:
package de.vogella.jersey.first;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
#Path("/hello")
public class Hello {
// This method is called if TEXT_PLAIN is request
#GET
#Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
return "Hello Jersey";
}
// This method is called if XML is request
#GET
#Produces(MediaType.TEXT_XML)
public String sayXMLHello() {
return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";
}
// This method is called if HTML is request
#GET
#Produces(MediaType.TEXT_HTML)
public String sayHtmlHello() {
return "<html> " + "<title>" + "Hello Jersey" + "</title>"
+ "<body><h1>" + "Hello Jersey" + "</body></h1>" + "</html> ";
}
}
here is the web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>de.vogella.jersey.first</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>de.vogella.jersey.first</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
here are the libraries that I have added from Jersey:
asm-all-repackaged-2.2.0-b14.jar
cglib-2.2.0-b14.jar
guava-14.0.1.jar
hk2-api-2.2.0-b14.jar
hk2-locator-2.2.0-b14.jar
hk2-utils-2.2.0-b14.jar
javax.annotation-api-1.2.jar
javax.inject-2.2.0-b14.jar
javax.servlet-api-3.0.1.jar
javax.ws.rs-api-2.0.jar
jaxb-api-2.2.7.jar
jersey-client.jar
jersey-common.jar
jersey-container-servlet-core.jar
jersey-container-servlet.jar
jersey-server.jar
org.osgi.core-4.2.0.jar
osgi-resource-locator-1.0.1.jar
persistence-api-1.0.jar
validation-api-1.1.0.Final.jar
If you are using jersey 2.x API, you need to rename the classes as done below, and your issue will be resolved.
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>org.glassfish.jersey.config.property.packages</param-name>
<param-value>com.practise.rest</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Karthik [aka DjNickZ]
You are getting
com.sun.jersey.spi.container.servlet.ServletContainer
That means you are using different version of jar. You added jersey-server.jar this jar is upgrade to jersey-servlet-1.17.jar.
So add jersey-servlet-1.17.jar to your project.
We get this error because of build path issue. You should add "Server Runtime" libraries in Build Path.
"java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer"
Please follow below steps to resolve class not found exception.
Right click on project --> Build Path --> Java Build Path --> Add Library --> Server Runtime --> Apache Tomcat v7.0
Thanks,
Sachin G N
You need to add the following jar files to your web-inf/lib folder, also you need to configure build path -- Right click your project--Build path -- configure build path -- libraries -- add external jars (add all the below jar files). And restart server

java.lang.IllegalArgumentException: The servlets named [X] and [Y] are both mapped to the url-pattern [/url] which is not permitted

I tried to add this servlet
package com.classmgt.servlet;
#WebServlet("/ControllerServlet")
public class ControllerServlet extends HttpServlet {}
to my Eclipse project, by editing the web.xml as below
<servlet>
<description>Servlet to print out Hello World!</description>
<display-name>ControllerServlet</display-name>
<servlet-name>ControllerServlet</servlet-name>
<servlet-class>com.classmgt.servlet.ControllerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ControllerServlet</servlet-name>
<url-pattern>/ControllerServlet</url-pattern>
</servlet-mapping>
However, I got the following exception:
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/ClassManagementSystem]]
at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
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: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/ClassManagementSystem]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
... 7 more
Caused by: java.lang.IllegalArgumentException: The servlets named [ControllerServlet] and [com.classmgt.servlet.ControllerServlet] are both mapped to the url-pattern [/ControllerServlet] which is not permitted
at org.apache.catalina.deploy.WebXml.addServletMapping(WebXml.java:335)
at org.apache.catalina.startup.ContextConfig.processAnnotationWebServlet(ContextConfig.java:2457)
at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2139)
at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2100)
at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2093)
at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2093)
at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2093)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1300)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:369)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5269)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 7 more
I have tried adding metadata-complete="true" to web.xml, but it does not recognize the servlet anymore.
Caused by: java.lang.IllegalArgumentException: The servlets named
[ControllerServlet] and [com.classmgt.servlet.ControllerServlet] are
both mapped to the url-pattern [/ControllerServlet] which is not
permitted
It seems that you have mixed #WebServlet annotation based and web.xml based configuration.
I doubt that you created a Servlet using the "Create Servlet" wizard which creates web.xml entry with url-pattern and then , added a #WebServlet annotation which duplicates anything you may put in the web.xml.
You should use the one or the other, not both. Remove the mapping from web.xml and go ahead with using only the #WebServlet annotation.
Read more: Servlet 3.0 Annotations and our Servlets wiki page.
Just remove the annotation #WebServlet("/ControllerServlet"), from the ControllerServlet, because it already added in the web.xml.
java.lang.IllegalArgumentException: The servlets named...
I fetched this cause where I create new servlet in different package (name='syncro'). My servlet located in syncro.SynchronizeServlet
And when I add information about this servlet in deployment descriptor (web.xml) I catch error: IllegalArgumentException
Example of incorrect descriptor part:
<servlet>
<description></description>
<display-name>SynchronizeServlet</display-name>
<servlet-name>SynchronizeServlet</servlet-name>
<servlet-class>SynchronizeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SynchronizeServlet</servlet-name>
<url-pattern>/SynchronizeServlet</url-pattern>
<url-pattern>/SynServlet</url-pattern>
</servlet-mapping>
When I add correct path for servlet - error disappeared. Correct desc below:
<servlet>
<description></description>
<display-name>syncro.SynchronizeServlet</display-name>
<servlet-name>syncro.SynchronizeServlet</servlet-name>
<servlet-class>syncro.SynchronizeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>syncro.SynchronizeServlet</servlet-name>
<url-pattern>/SynchronizeServlet</url-pattern>
<url-pattern>/SynServlet</url-pattern>
</servlet-mapping>
==> 73!
What worked for me is doing a 'clean'.
My issue was caused when the Servlet class was renamed. However, the original .class files remained in the target directory (with their Servlet annotation). It looks like you moved your ControllerServlet into a package.
Jetty didn't seem to mind these apparent duplicates, but Tomcat7 gave your
'both mapped to the url-pattern' exception.
The easy way to see if this is causing your issue is to look in the WAR to see if both the old classes (in your case [ControllerServlet] and [com.classmgt.servlet.ControllerServlet]) are both there.
As for me I added the tom-cat version to my pom file and it worked
<properties>
<tomcat.version>7.0.52</tomcat.version>
</properties>
<dependencies>
The servlets named [Register] and [com.TeamWork.controller.Register]
are both mapped to the url-pattern [/Register] which is not permitted
getting this error you have to remove your servlet mapping from web.xml and just add #WebServlet("/Register") annotation + url
<servlet>
<servlet-name>Register</servlet-name>
<servlet-class>com.TeamWork.controller</servlet-class>
</servlet>
then your servlet class on the top add this one
#WebServlet("/Register")`
public class Register extends HttpServlet { }
it will work thanks
For me, it was an unexpected error in Intellij Idea.
I deleted a servlet 2 days back which was having the same URL pattern. However, I am getting the error that my new servlet and that deleted one have the same URL pattern. This was strange.
Tried cleaning the Tomcat v10.0.23 server,
Restarted the server,
Build the exploded artifact,
Restarted IDE.
Nothing works!!
Finally, I run the project in debug mode and that fix my issue.
This is strange but maybe I did something wrong that's why I faced this issue.
Hope this can help someone if they're facing the same issue.

Problems in creating JSF project in eclipse [duplicate]

I'm using this :
Tomcat 7.0
JSF 2.0
JRE 7
but when trying to run my application, I got the following exception:
java.lang.IllegalStateException: Could not find backup for factory javax.faces.application.ApplicationFactory.
at javax.faces.FactoryFinder$FactoryManager.getFactory(FactoryFinder.java:1011)
at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:343)
at org.apache.myfaces.context.servlet.FacesContextImplBase.getApplication(FacesContextImplBase.java:159)
at org.apache.myfaces.context.servlet.FacesContextImplBase.getELContext(FacesContextImplBase.java:210)
at javax.faces.component.UIViewRoot.setLocale(UIViewRoot.java:1463)
at org.apache.myfaces.webapp.AbstractFacesInitializer._createFacesContext(AbstractFacesInitializer.java:477)
at org.apache.myfaces.webapp.AbstractFacesInitializer.initStartupFacesContext(AbstractFacesInitializer.java:449)
at org.apache.myfaces.webapp.StartupServletContextListener.contextInitialized(StartupServletContextListener.java:113)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
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)
Any ideas why?
Thanks,
That may happen if your webapp's runtime classpath is polluted with multiple JSF impls/versions. The org.apache.myfaces entries in the stack trace tells that you're using MyFaces. This problem thus suggests that you've another JSF implementation like Mojarra in the webapp's runtime classpath which is conflicting with it. It's recognizable by jsf-api.jar, or jsf-impl.jar, or javax.faces.jar. If you remove all of them, then this problem should disappear.
Or, if you actually intented to use Mojarra instead of MyFaces (you did namely not explicitly state the intented JSF impl/version anywhere in your question, but you just generically stated the JSF spec as in "JSF 2.0", so perhaps you actually had no clue what you was all doing), then you should be removing myfaces-*.jar files from your webapp.
See also:
JSF wiki page - Installing JSF
How to properly install and configure JSF libraries via Maven?
Difference between Mojarra and MyFaces
JSF implementations and component libraries
Complementing BalusC's answer, I recently got this error when trying to run an independent JAR with a Spring Boot application that has JSF as front-end with Spring-managed beans. Switching the packaging from JAR to WAR solved the problem.
For me {Tomcat 8, JSF 2.2, JRE 8}, the following steps worked:
Download JSTL jars API && IMPL and place it in your Tomcat lib.
Since downloading Majorra directly from eclipse in project
facets configuration is recently impossible ; "Zip File is empty Exception",
manually download jsf-api.jar and jsf-impl.jar and include them in a
new user library added to build path(only once!).
This is my 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" id="WebApp_ID" version="3.1">
<display-name>TestJSF</display-name>
<welcome-file-list>
<welcome-file>index.xhtml</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>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
</web-app>
In addition to what's already said, I faced this issue when importing a third party project, the reason was that two profiles were defined in the pom.xml, one for My Faces and another for Mojarra.
If this is your case, you just need to select one of them with maven -P or in Project properties, Maven section, indicating the profile(s) to be used.
In my case this exception was caused on webapp shutdown by the presence of com.sun.faces.config.ConfigureListener in web.xml, running Mojarra 2.2.x under Tomcat 8.0. As described in this answer, this causes Tomcat to register that listener twice (both automatically and by virtue of the web.xml entry) and hence, among other things, its contextDestroyed method is executed twice, the second time producing the described exception (most probably because JSF was already shut down by the first listener registration).
I had no classpath conflict in my case: just one version of Mojarra (2.2.6) and no MyFaces.