简体   繁体   中英

Tomcat: SEVERE: Error loading WebappClassLoader

PLEASE DO NOT MARK AS DUPLICATE, FOR OTHER SOLUTIONS DID NOT HELP YET!

I'm getting 404 in my browser trying to run this tutorial: http://www.vogella.com/articles/REST/article.html

I actually do not even see a WebContent/WEB-INF/classes folder. Why isn't it generated?

I only saw solutions here on SO telling to clean the project, restart Eclipse, and so on... But non helped in my situation. I'm using Tomcat 6, dynamic web module version 2.5.

May 13, 2013 8:17:01 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
May 13, 2013 8:17:01 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:de.vogella.jersey.first' did not find a matching property.
May 13, 2013 8:17:02 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
May 13, 2013 8:17:02 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 524 ms
May 13, 2013 8:17:02 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
May 13, 2013 8:17:02 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.37
May 13, 2013 8:17:02 PM com.sun.jersey.api.core.PackagesResourceConfig init
INFO: Scanning for root resource and provider classes in the packages:
  de.vogella.jersey.first
May 13, 2013 8:17:02 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
  class de.vogella.jersey.first.Hello
May 13, 2013 8:17:02 PM com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
May 13, 2013 8:17:02 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.17 01/17/2013 03:31 PM'
May 13, 2013 8:17:03 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
May 13, 2013 8:17:03 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
May 13, 2013 8:17:03 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/15  config=null
May 13, 2013 8:17:03 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1145 ms

And there is still no classes folder!!!

Vogel's example is using Jersey 1.5. If you are using Jersey 2.0 & Servlet 2.X, some properties in the web.xml file need to be changed. The web-app properties should reflect the Servlet version you are using. Also, the ServletContainer is now in the org.glassfish.jersey.servlet package. So the servlet-class property should be specified as follows:

<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> 

For example, for Servlet 2.5, the web.xml file should look like this:

<?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"  
  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">
  <display-name>de.vogella.jersey.first</display-name>
  <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>jersey.config.server.provider.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/hello</url-pattern>
  </servlet-mapping>
</web-app>

This information can be found in the Jersey 2.0 User Guide , Chapter 4, Deploying a RESTful Web Service.

Also, I found that I needed to set the url-pattern to:

    <url-pattern>/rest/hello</url-pattern>

to get it to work, so I still need to investigate this issue.

I too had the same problem; however, I've was stuck for a day. It is because of the versions of the jars most likely. I had set a jar which was probably picked up 1st. in the class path and it was the wrong version of course, or compiled with a different version of Java maybe. I've seen this before. So I started over from scratch paying attention to the jars and versions numbers installing only what was needed and it worked like a champ. ;)

Try these steps (hope you are using Eclipse) and see if it helps getting closer to the issue.

  1. Navigate:: "Right Click (project Name) --> Properties --> Source" Tab and make sure "project/WebContent/WEB-INF/classes" is selected as default output folder.

  2. Navigate "Window(Menu) --> Show View --> Other --> General --> Navigator" and then go to "project/WebContent/WEB-INF/" and check if "classes" folder is there are not.

  3. If not, then navigate "Window(Menu) --> Show View --> Other --> General --> Markers" and see if its showing any build path errors. If so, correct the errors and you should be good.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM