Class loading errors using Jetty
March 20th, 2009
Applies to:
Jetty
Description:
Occurs while using Jetty
Cause:
Class loading in a web container is slightly more complex than a normal java application. Probably You have incorrect configuration.
Applies to:
Jetty
Description:
Occurs while using Jetty
Cause:
Class loading in a web container is slightly more complex than a normal java application. Probably You have incorrect configuration.
JAVA-Jetty classloading in jetty, for input string: ../webapp/web-inf/classes/jetty.xml, j, java, java.lang.classnotfoundexception: web-inf.c, jetty 6 class loading, jetty application class not having priority, jetty class load web-inf/lib -embed, jetty class loading errors, jetty class loading priority, jetty classloading, jetty classloading change priority, jetty classloading server classes, jetty issue in loading classes from web-inf/classes, jetty loading from web-inf/classes, jetty loadings, jetty setserverclasses, jetty system classes configure, jetty web application class loader, jetty web inf classes, jetty web-inf/classes classloader, jetty web-inf/classes web-inf/lib priority, jetty web-inf/lib vs web-inf/classes, jetty7 classloading errors, lrm-00118: syntax error at '=' at the end of input, this is very useful if the libraries that a web application uses are having problems loading classes that are both in a web application and on the system classpath., using own classloader jetty, web-inf/lib priority
The normal configuration is for each web context (webapplication or war file) is given it’s own classloader, which has the system classloader as it’s parent. Such a classloader hierarchy is normal in Java, however the servlet specification complicates the hierarchy by requiring that:
* Classes contained within WEB-INF/lib or WEB-INF/classes have priority over classes on the parent class loader. This is the opposite of the normal behaviour of a java 2 class loader.
* System classes such as java.lang.String may not be replaced by classes in WEB-INF/lib or WEB-INF/classes. Unfortunately the specification does not clearly state what classes are “System” classes and it is unclear if all javax classes should be treated as System classes.
* Server implementation classes should be hidden from the web application and should not be available in any class loader. Unfortunately the specification does not state what is a Server class and it is unclear if common libraries like the xerces parser should be treated as Implementation classes.
Jetty provides configuration options to control all three of these options. The method org.mortbay.http.HttpContext.setClassLoaderJava2Compliant(boolean) allows the normal java 2 behaviour to be used and all classes will be loaded from the system classpath if possible. This is very useful if the libraries that a web application uses are having problems loading classes that are both in a web application and on the system classpath.
The methods setSystemClasses(String[]) and setServerClasses(String[]) may be called on either the org.mortbay.http.HttpServer or org.mortbay.http.HttpContext class to configure the whole server or just a particular context. This allows fine control over what classes can be seen or overridden by a web application. Absolute classname can be passed, names ending with . are treated as packages names and names starting with – are treated as negative matches.
These configuration may be setup either in code, in jetty.xml or in a jetty-web.xml file. An example for jetty.xml is below: