Servlet Mapping and deploying in Tomcat - java

I am developing a simple servlet based web application. I am not using any IDE. Following are the steps that i have followed.
Folder Structure :
MyAPP -> Contains WEB-INF folder and index.html
WEB-INF contains 2 folders and web.xml.
Path to loginServlet.java : MyAPP\WEB-INF\classes\servletclass\loginServlet.java
WEB_INF contains lib folder which conatins servlet-api.jar
index.html contains a form and the action attribute of the form contains "login" as value.
MyAPP\WEB-INF\web.xml looks like below :
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>loginServlet</servlet-name>
<servlet-class>servletclass.loginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>loginServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
Compiled the loginServlet.java using command prompt. It created a loginServlet.class file.
Now built a war file using command prompt and deployed it on Tomcat server.
Now when i run the application, it succesfully loads index.html. But as soon as click on Submit button in the form it shows the following error:
java.lang.NoClassDefFoundError: servletclass/loginServlet (wrong name: loginServlet)
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(Unknown Source)
java.security.SecureClassLoader.defineClass(Unknown Source)
org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2260)
org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:803)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1244)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1109)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:456)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784)
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1452)
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
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)

Alan is right, do you have the following declaration in your Java file?
package servletclass;

Related

IncompatibleClassChangeError: Implementing class in struts 2.5.13

Following struts jars are used in project:
activation.jar, asm-5.2.jar, asm-commons-5.2.jar ,asm-tree-5.2.jar, commons-beanutils-1.9.2.jar , commons-collections-3.2.2.jar, commons-fileupload-1.3.3.jar , commons-io-2.5.jar , commons-lang-2.5.jar, commons-lang3-3.6.jar, commons-logging-1.1.3.jar, commons-logging-api-1.1.jar , freemarker-2.3.23.jar, javassist-3.20.0-GA.jar , javax.servlet.jar ,log4j-api-2.8.2.jar mail.jar , ognl-3.1.15.jar, struts2-convention-plugin-2.5.13.jar , struts2-core-2.5.13.jar, struts2-rest-plugin-2.5.13.jar , xstream-1.4.10.jar, xwork-core-2.3.34.jar
also tomcat 8.5 and java 8 installed on system.
I am getting the following error after startup, anyone got any ideas please!!!
04-Dec-2017 11:17:29.066 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.filterStart Exception starting filter [struts2]
Unable to load configuration. - bean - jar:file:/apache-tomcat-8.5.23/webapps/WebTool/WEB-INF/lib/struts2-core-2.5.13.jar!/struts-default.xml:137:154
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:512)
at org.apache.struts2.dispatcher.InitOperations.initDispatcher(InitOperations.java:75)
at org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:63)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:285)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:266)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4591)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5233)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1144)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1878)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: Unable to load bean: type:com.opensymphony.xwork2.TextProviderFactory class:com.opensymphony.xwork2.StrutsTextProviderFactory - bean - jar:file:/apache-tomcat-8.5.23/webapps/WebTool/WEB-INF/lib/struts2-core-2.5.13.jar!/struts-default.xml:137:154
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:247)
at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:98)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:240)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
... 21 more
Caused by: java.lang.IncompatibleClassChangeError: Implementing class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2283)
at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:811)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1260)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at com.opensymphony.xwork2.util.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:144)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:218)
... 24 more
Any help will be appreciated.
Here is my web.xml structure :
I have updated the filter dispatcher to the newest statement
org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
<?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>WebTool</display-name>
<welcome-file-list>
<welcome-file>Home.html</welcome-file>
</welcome-file-list>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/WEBTOOLDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>actionPackages</param-name>
<param-value>com.webtool.ktt.servlet</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Encountered the same problem. It turned out to be due to having both struts2-core (v2.5.14.1) and xwork-core (2.3.34) as dependencies.
struts2-core.jar since v2.5 contains TextProviderFactory as an interface, but xwork-core had the older version of the same class as a true class.
Dropping the xwork-core dependency solved the problem for me.

class path resource [java/lang/Object.class] cannot be opened because it does not exist

I am having a strange issue with a Spring web application. This is from the Tomcat log:
GRAVE: Exception lors de l'envoi de l'évènement contexte initialisé (context initialized) à l'instance de classe d'écoute (listener) org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: com.jverstry.Configuration.WebConfig; nested exception is java.io.FileNotFoundException: class path resource [java/lang/Object.class] cannot be opened because it does not exist
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:267)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:203)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:622)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1247)
at org.apache.catalina.manager.HTMLManagerServlet.start(HTMLManagerServlet.java:714)
at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:219)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:186)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:581)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1770)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: class path resource [java/lang/Object.class] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:157)
at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:49)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80)
at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:101)
at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:76)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:257)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:149)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:126)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:219)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:149)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:126)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:263)
... 36 more
16-sept.-2012 15:51:56 org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
I have seen similar questions on SO, but none related to java/lang/Object.class. I hae no idea what is causing this.
This is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.jverstry.Configuration</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>mytest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/mytest/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file></welcome-file>
</welcome-file-list>
</web-app>
Here is my WebConfig class:
#EnableWebMvc
#Configuration
#ComponentScan(basePackages = {"com.jverstry", "org.krams"})
#ImportResource("WEB-INF/spring-security.xml")
public class WebConfig extends WebMvcConfigurerAdapter {
#Bean
public ViewResolver getViewResolver() {
InternalResourceViewResolver resolver
= new InternalResourceViewResolver();
resolver.setPrefix("WEB-INF/pages/");
resolver.setSuffix(".jsp");
return resolver;
}
}
That is most peculiar.
Lets start with the what we do know. The class java.lang.Object and the corresponding java/lang/Object.class file most certainly do exist. If they didn't then is is highly unlikely that the JVM would have started in the first place.
So how come you get the exception?
My theory it that somewhere in your codebase (or the libraries you are using) there is a classloader that is breaking the rules. When it is asked to load a resource, a well behaved class loader will first delegate up the class loader chain to see if its parent classloader can load the resource. I suspect that what is happening is that the broken classloader is skipping the delegation step and just trying to load the resource itself. If the "rt.jar" is not on its list of JARs, etc (and it normally won't be) then the class loader won't find the Object.class file ... and you will get a FileNotFoundException.
UPDATE
I think I understand. If your Java installation was corrupted to the extent that it couldn't load java.lang.Object, then the JVM wouldn't boot. And if it had already booted before the corruption, then it wouldn't be trying to load the Object class.
But it is not trying to do that. It is actually trying to read the Object.class file. And the stacktrace seem to be saying that this is occurring in Spring's annotation processing code.
So I think that something has triggered a servlet restart after the Java installation was compromised. And the restart caused the spring configuration to be done again. Why it worked when you rebooted is a mystery ... unless the problem was due to a hardware error or stuck device driver that was cleared by the reboot.
(The post you found describes a different scenario ... where the JVM fail during its bootstrap. Your scenario is more complicated.)
It turns out my JRE6 installation was somehow corrupted. I reinstalled it manually and now I don't have an issue anymore. I have also found another post which might explain why the issue would disappear after rebooting.

Tomcat error when using Tomcat-Deployer on Eclipse

When i deploy my application via a WAR file on my tomcat server, the application runs perfectly, However when i use Tomcat Deployer plugin which deploys the directories instead of a WAR file i get the following error.
javax.servlet.ServletException: Wrapper cannot find servlet class org.code.KathyServlet or a class it depends on
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Thread.java:662)
root cause
java.lang.ClassNotFoundException: org.code.KathyServlet
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:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Proto col.java:602)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Thread.java:662)
I have tried giving it a class-path in the MANIFEST file but it did not make a difference.
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_3_0.xsd" version="3.0">
<display-name>HFJse</display-name>
<servlet>
<servlet-name>KathyServlet</servlet-name>
<servlet-class>org.code.KathyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>KathyServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>

Tomcat 5.5 Don't Find My Servlet

I've compiled the source into the class Files, then putted at the folder:
Tomcat 5.5\WEB-INF\ROOT\classes\Files.class
And added this to the web.xml file:
<servlet>
<servlet-name>Files</servlet-name>
<servlet-class>Files</servlet-class>
</servlet>
But when I tried to access the URL http://localhost:8080/Files, I got this error from Tomcat:
Tomcat 5.5 404 Error http://img251.imageshack.us/img251/5042/tomcat404.png
Update: after adding <servlet-mapping> I'm now getting the following error:
exception
javax.servlet.ServletException: Error allocating a servlet instance
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:837)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:640)
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1287)
java.lang.Thread.run(Unknown Source)
root cause
java.lang.NoClassDefFoundError: IllegalName: /Files
java.lang.ClassLoader.preDefineClass(Unknown Source)
java.lang.ClassLoader.defineClassCond(Unknown Source)
java.lang.ClassLoader.defineClass(Unknown Source)
java.security.SecureClassLoader.defineClass(Unknown Source)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1960)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:931)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1405)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1284)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:837)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:640)
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1287)
java.lang.Thread.run(Unknown Source)
root cause
java.lang.NoClassDefFoundError: IllegalName: /Files
This means that the given class definition cannot be found because it has an illegal name /Files. This in turn means that you've changed the <servlet-class> to /Files. This is wrong. You're basically instructing the servletcontainer to declare and instantiate the servlet as follows:
/Files Files = new /Files();
This won't already compile. The complete mapping should look like:
<servlet>
<servlet-name>instanceName</servlet-name>
<servlet-class>com.example.ServletClass</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>instanceName</servlet-name>
<url-pattern>/urlPattern</url-pattern>
</servlet-mapping>
Which is to be interpreted in raw Java code as follows:
com.example.ServletClass instanceName = new com.example.ServletClass();
The <servlet-class> should denote the full qualified classname, including any package. The <servlet-name> should denote the unique instance name. The <url-pattern> should denote the URL pattern for which the servletcontainer should invoke this servlet.
You also need to define a
<servlet-mapping>
<servlet-name>Files</servlet-name>
<url-pattern>/Files</url-pattern>
</servlet-mapping>
To match the url pattern to the servlet
You also need the servlet-mapping:
<servlet-mapping>
<servlet-name>Files</servlet-name>
<url-pattern>/Files</url-pattern>
</servlet-mapping>
Also, in you classes folder under WEB-INF, make sure you make a folder whose name is the same as the package name of the classes and put all the classes in that folder. In web.xml, use
<servlet>
<servlet-name>File</servlet-name>
<servlet-class>package.File</servlet-class>
</servlet>
to reference you servlet in the classes folder

Deploying Jersey-enabled servlet to Tomcat: Exceptions

Here is what I'm trying to do: we are switching over to using JAXB and Jersey for all our REST services and XML/JSON serialization needs.
So far, I have been able to get a simple test working where some beans are annotated, some test objects created and these are perfectly serialized to either XML or JSON and return to the client upon request. I mostly wrote this based on some of the examples around the Internet, where the an HTTPServer is created and started in the main method.
I am now trying to put this same example into a WAR file and deploy it to my local Tomcat server so I can test it in a more production-like environment. Seeing as I was not able to get it to work on Tomcat 5.5.27 following the instructions here I went ahead and upgraded to Tomcat 6.0. Same instructions, same outcome, a huge InvocationTargetException.
What exactly am I missing guys?
INFO: Scanning for root resource and provider classes in the paths:
/Library/Tomcat/Home/webapps/user/WEB-INF/lib
/Library/Tomcat/Home/webapps/user/WEB-INF/classes
Sep 9, 2009 7:22:32 PM com.sun.jersey.api.core.ClasspathResourceConfig init
INFO: Root resource classes found:
class example.HelloWorld
Sep 9, 2009 7:22:32 PM com.sun.jersey.api.core.ClasspathResourceConfig init
INFO: Provider classes found:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.sun.jersey.impl.application.WebApplicationImpl$DefaultComponentProvider.getInstance(WebApplicationImpl.java:437)
at com.sun.jersey.impl.application.ComponentProviderCache.getComponent(ComponentProviderCache.java:187)
at com.sun.jersey.impl.application.ComponentProviderCache.getProvidersAndServices(ComponentProviderCache.java:122)
at com.sun.jersey.impl.application.InjectableProviderFactory.configure(InjectableProviderFactory.java:113)
at com.sun.jersey.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:582)
at com.sun.jersey.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:487)
at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:622)
at com.sun.jersey.spi.container.servlet.ServletContainer.load(ServletContainer.java:538)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:197)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4149)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4458)
That's part of the ginormous spew in catalina.out.
Also, here is my 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_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>ServletAdaptor</servlet-name>
<servlet-class>com.sun.jersey.impl.container.servlet.ServletAdaptor</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ServletAdaptor</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
Any help with this would be greatly appreciated! Thanks in advance.
You have probably a conflict somewhere, check your jar files and see if there are no duplicate classes. Use Tattletale to locate the problem
**Caused by: java.lang.NoSuchMethodError: javax.ws.rs.ext.Providers.getContextResolver(Ljava/lang/Class;Ljavax/ws/rs/core/MediaType;)Ljavax/ws/rs/ext/ContextResolver;**
at com.sun.jersey.impl.provider.entity.AbstractJAXBProvider.<init>(AbstractJAXBProvider.java:81)
at com.sun.jersey.impl.provider.entity.AbstractRootElementProvider.<init>(AbstractRootElementProvider.java:67)
at com.sun.jersey.impl.provider.entity.XMLRootElementProvider.<init>(XMLRootElementProvider.java:66)
at com.sun.jersey.impl.provider.entity.XMLRootElementProvider$App.<init>(XMLRootElementProvider.java:72)
... 41 more

Categories