java.lang.ClassNotFoundException: bachelor.ActionServlet [duplicate] - eclipse

This question already has an answer here:
Eclipse does not seem to compile servlet, causing java.lang.ClassNotFoundException
(1 answer)
Closed 6 years ago.
I know that this kind of question was asked a view times. But I read many posts about this and couldn't find the right answer to fix my problem.
I have this 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>Name</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>ActionServlet</servlet-name>
<servlet-class>bachelor.ActionServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ActionServlet</servlet-name>
<url-pattern>/ActionServlet/*</url-pattern>
</servlet-mapping>
</web-app>
And of course there is the ActionServlet.java in the Folder: Java Resources/src/bachelor/ActionServlet.java
But when my index.jsp does this javascript:
$.get('ActionServlet',{user:username},function(responseText) {
$('#welcometext').text(responseText);
});
I get the following error when runnig it in eclipse.
java.lang.ClassNotFoundException: bachelor.ActionServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:532)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:514)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:142)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:865)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Does anyone know why I get this error? Thanks for your help!

Hence BalusC doesn't write an answer. Here is his answer:
Apparently the project is not built. Can you ensure that the option
Project > Build Automatically is checked?
Building the project fixed the problem.

Related

java.lang.ClassNotFoundException: org.springframework.core.NestedRuntimeException [duplicate]

This question already has answers here:
How to add JAR libraries to WAR project without facing java.lang.ClassNotFoundException? Classpath vs Build Path vs /WEB-INF/lib
(5 answers)
Closed 6 years ago.
i am trying to run tomcat on my web application but i cannot, can someone help me to find the problem.
Caused by: java.lang.NoClassDefFoundError: org/springframework/core/NestedRuntimeException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2957)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1210)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1690)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Unknown Source)
at java.lang.Class.getDeclaredFields(Unknown Source)
at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:106)
at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:261)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationServletAnnotations(WebAnnotationSet.java:140)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:65)
at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:403)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:879)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:374)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5355)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
Caused by: java.lang.ClassNotFoundException: org.springframework.core.NestedRuntimeException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
... 27 more
the web.xml file
<?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_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>TargetDestroy_Hospi</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/servlet-context.xml</param-value>
</context-param>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
Server Tomcat v7.0 Server at localhost failed to start.
the last week everything was ok but since yesterday tomcat cannot start
make sure that you written correct URL in servlet Program
Example: #WebServlet("/URL")
If you missed '/' it gives tomcat server error

IllegalArgumentException: The servlets named [Test] and [com.srk.pkg.MyServlet] are both mapped to the url-pattern [/MyServlet] which is not permitted [duplicate]

This question already has answers here:
java.lang.IllegalArgumentException: The servlets named [X] and [Y] are both mapped to the url-pattern [/url] which is not permitted
(7 answers)
Closed 7 years ago.
Starting Tomcat v8.0 server at localhost encountered a problem.
apache fails to start when web app's project web.xml contains servlet info:
<?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>WebApp-01</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>Test</servlet-name>
<servlet-class>com.srk.pkg.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/MyServlet</url-pattern>
</servlet-mapping>
</web-app>
when servlet info is removed from web.xml, it s all right, app gets deployed, browser opens...
<?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>WebApp-01</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>
</web-app>
server log:
Caused by: java.lang.IllegalArgumentException: The servlets named [Test] and [com.srk.pkg.MyServlet] are both mapped to the url-pattern [/MyServlet] which is not permitted
at org.apache.tomcat.util.descriptor.web.WebXml.addServletMapping(WebXml.java:308)
at org.apache.catalina.startup.ContextConfig.processAnnotationWebServlet(ContextConfig.java:2325)
at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2007)
at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:1901)
at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:1896)
at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:1896)
at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:1896)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1139)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:771)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:305)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5095)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
I think that you can't have the same servlet mapping defined twice: in annotation and in web.xml.
When you add #WebServlet annotation for servlet class you dont't have to put it again in web.xml. Servlets with that annotations get started automatically.
Sometime this problem can also be solved by just deleting server and adding server back. When you delete the server do not forget that you also have to delete the "runtime environments" of the server.
Hope this helps :)

The servlets named [AdminValidate] and [com.kunal.servlet.AdminValidate] are both mapped to the url-pattern [/AdminValidate] which is not permitted [duplicate]

This question already has answers here:
java.lang.IllegalArgumentException: The servlets named [X] and [Y] are both mapped to the url-pattern [/url] which is not permitted
(7 answers)
Closed 6 years ago.
When ever I try to execute certain files in my Project I get this error
"Server Tomcat v7.0 Server at localhost failed to start"
The console shows following errors
Caused by: java.lang.IllegalArgumentException: The servlets named [AdminValidate] and [com.kunal.servlet.AdminValidate] are both mapped to the url-pattern [/AdminValidate] which is not permitted
at org.apache.catalina.deploy.WebXml.addServletMapping(WebXml.java:293)
at org.apache.catalina.startup.ContextConfig.processAnnotationWebServlet(ContextConfig.java:2396)
at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2072)
at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2033)
at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2026)
at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2026)
at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2026)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1291)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:876)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:374)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5378)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
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" id="WebApp_ID" version="3.0">
<display-name>Agro</display-name>
<servlet>
<display-name>AdminValidate</display-name>
<servlet-name>AdminValidate</servlet-name>
<servlet-class>com.kunal.servlet.AdminValidate</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AdminValidate</servlet-name>
<url-pattern>/AdminValidate</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 tried all the solution on stackoverflow but nothing seems to help...if there is any other solution to this problem please post here.
Comments have provided the answers, still i would like to post as an answer
Caused by: java.lang.IllegalArgumentException: The servlets named [AdminValidate] and [com.kunal.servlet.AdminValidate] are both mapped to the url-pattern [/AdminValidate] which is not permitted
How would you expect the container to choose one servlet for an URL, when you have provided more than one servlet for the same URL pattern?
Please check the web.xml for more than one servlet mapped to the same URL pattern.
Think.

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

This question already has answers here:
java.lang.IllegalArgumentException: The servlets named [X] and [Y] are both mapped to the url-pattern [/url] which is not permitted
(7 answers)
Closed 6 years ago.
I can not start Tomcat: Server Tomcat v7.0 Server at localhost failed to start.
Caused by: java.lang.IllegalArgumentException: The servlets named [CreationClient] and [com.sdz.tp.servlets.CreationClient] are both mapped to the url-pattern [/CreationClient] which is not permitted
at org.apache.catalina.deploy.WebXml.addServletMapping(WebXml.java:335)
at org.apache.catalina.startup.ContextConfig.processAnnotationWebServlet(ContextConfig.java:2466)
at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2148)
at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2109)
at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2102)
at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2102)
at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2102)
at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2102)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1293)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:376)
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:5322)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 7 more
4 janv. 2014 19:57:38 org.apache.catalina.core.ContainerBase startInternal
The problem is probably with 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"
id="WebApp_ID" version="3.0">
<display-name>tp1</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>CreationClient</servlet-name>
<servlet-class>com.sdz.tp.servlets.CreationClient</servlet-class>
</servlet>
<servlet>
<servlet-name>CreationCommande</servlet-name>
<servlet-class>com.sdz.tp.servlets.CreationCommande</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CreationClient</servlet-name>
<url-pattern>/CreationClient</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CreationCommande</servlet-name>
<url-pattern>/CreationCommande</url-pattern>
</servlet-mapping>
</web-app>
Could someone tell me what's wrong?
Try removing the #WebServlet annotation from class com.sdz.tp.servlets.CreationClient. The servlet mapping can be defined either in web.xml or using an annotation, but not both.

Tomcat: Class not found exception

I'm developing a servlet running on Tomcat 6 using Eclipse as IDE.
The main path of the web application is "Calcolatrice" and the name of the servlet id "Calcolatrice" too.
When I try to execute a simple get operation on the servlet the following exception is throwed:
javax.servlet.ServletException: Wrapper cannot find servlet class as.unibo.Calcolatrice or a class it depends on
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Thread.java:680)
root cause
java.lang.ClassNotFoundException: as.unibo.Calcolatrice
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Thread.java:680)
What I cannot understand is why the package where is the servlet is "as.unibo.polac.server" but Tomcat searches it in another package "as.unibo".
Which could be the reason of this problem?
[EDIT]
This is the content of my web.xml file:
<?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>Calcolatrice</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>
<description></description>
<display-name>Calcolatrice</display-name>
<servlet-name>Calcolatrice</servlet-name>
<servlet-class>as.unibo.Calcolatrice</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Calcolatrice</servlet-name>
<url-pattern>/Calcolatrice</url-pattern>
</servlet-mapping>
</web-app>
Is it correct?
Because your servlet is in as.unibo.polac.server package your web.xml should be:
....
<servlet>
<description></description>
<display-name>Calcolatrice</display-name>
<servlet-name>Calcolatrice</servlet-name>
<servlet-class>as.unibo.polac.server.Calcolatrice</servlet-class>
</servlet>
.....
The class path is wrong in your web.xml. Update it.