现在的位置: 首页 > 综合 > 正文

不应该出现在web应用部署包中的jar文件

2013年10月18日 ⁄ 综合 ⁄ 共 4224字 ⁄ 字号 评论关闭
web应用出现如下错误:
javax.servlet.ServletException: loader constraint violation: when resolving method "org.apache.jasper.compiler.JspRuntimeContext.<init>(Ljavax/servlet/ServletContext;Lorg/apache/jasper/Options;)V" the class loader (instance of org/apache/catalina/loader/WebappClassLoader) of the current class, org/apache/jasper/servlet/JspServlet, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, org/apache/jasper/compiler/JspRuntimeContext, have different Class objects for the type org/apache/jasper/Options used in the signature
	org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:294)
	org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
	org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:115)
	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
	org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:542)
	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
	org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:834)
	org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:640)
	org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1286)
	java.lang.Thread.run(Thread.java:619)
	...

root cause 

java.lang.LinkageError: loader constraint violation: when resolving method "org.apache.jasper.compiler.JspRuntimeContext.<init>(Ljavax/servlet/ServletContext;Lorg/apache/jasper/Options;)V" the class loader (instance of org/apache/catalina/loader/WebappClassLoader) of the current class, org/apache/jasper/servlet/JspServlet, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, org/apache/jasper/compiler/JspRuntimeContext, have different Class objects for the type org/apache/jasper/Options used in the signature
	org.apache.jasper.servlet.JspServlet.init(JspServlet.java:76)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	java.lang.reflect.Method.invoke(Method.java:597)
	...
原因:

JAR files you should never include in your web-app

As a rule, the following jar files should never be part of your webapp:

  • j2ee.jar - interfaces are implemented by Tomcat
  • jasper-*.jar - causes Exceptions, or will do when version of Tomcat is upgraded
  • jboss.jar - part of jboss - should not be part of your app
  • jsp-api.jar - causes Exceptions, or will do when version of Tomcat is upgraded
  • gwt-user.jar - contains javax.servlet.Servlet, so gets ignored by Tomcat
  • gwt-dev-linux.jar - contains javax.servlet.Servlet, so gets ignored by Tomcat
  • gwt-dev-windows.jar - contains javax.servlet.Servlet, so gets ignored by Tomcat
  • rt.jar - not sure why you would, but some have...
  • servlet-api.jar - this is really old too, switch to compiling with j2ee.jar
  • servlet.jar - this is really old too, switch to compiling with j2ee.jar
  • tools.jar - part of VM

You may require these for compiling your app (notably servlet-api.jar or j2ee.jar), but they should not be deployed as part of your webapp.

jsp-api.jar and/or jasper-*.jar

Including these files will cause the following exceptions:

If these aren't thrown when deploying your app, they most likely will be when the version of Tomcat is next updated. By chance, you might be using exactly the same version as the container. They already exist in the container though, so remove them to save yourself future pain.

servlet-api.jar - the most common mistakenly included JAR

Many developers incorrectly include servlet-api.jar in their WEB-INF/lib folder. This no longer causes an exception because Tomcat and other app servers will recognize it as a problem when deploying the JAR file. However, it does cause the container to ignore any JAR file that contains the javax/servlet/Servlet.class. In this case, you will see the following warning in the system log:

INFO: validateJarFile(/path/app/WEB-INF/lib/servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
 

抱歉!评论已关闭.