web项目中遇到的Maven包依赖冲突问题解决

在搭建web项目时,出现一个比较诡异的问题,任何JSP页面突然都不能够正常地显示,系统爆出HTTP:500(服务器内部错误)的页面
 

HTTP Status 500 - java.lang.NoSuchMethodError: org.eclipse.jdt.internal.compiler.CompilationResult.getProblems()[Lorg/eclipse/jdt/core/compiler/IProblem;


type Exception report

message java.lang.NoSuchMethodError: org.eclipse.jdt.internal.compiler.CompilationResult.getProblems()[Lorg/eclipse/jdt/core/compiler/IProblem;

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: java.lang.NoSuchMethodError: org.eclipse.jdt.internal.compiler.CompilationResult.getProblems()[Lorg/eclipse/jdt/core/compiler/IProblem;
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:273)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
        org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
        org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:264)
        org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1208)
        org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:992)
        org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939)
        org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
        org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
        org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
        org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
        org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

 

root cause

 

Java代码   收藏代码
  1.   
Java代码   收藏代码
  1. java.lang.NoSuchMethodError: org.eclipse.jdt.internal.compiler.CompilationResult.getProblems()[Lorg/eclipse/jdt/core/compiler/IProblem;           
  2. org.apache.jasper.compiler.JDTCompiler$2.acceptResult(JDTCompiler.java:354) org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:480)       org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:425)  org.apache.jasper.compiler.Compiler.compile(Compiler.java:298)           
  3. org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)           
  4. org.apache.jasper.compiler.Compiler.compile(Compiler.java:265)           
  5. org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)           
  6. org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:299)           
  7. org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)           
  8. javax.servlet.http.HttpServlet.service(HttpServlet.java:727)           
  9. org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)      org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)           
  10. org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:264)           
  11. org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1208)           
  12. org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:992)           
  13. org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939)           
  14. org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)           
  15. org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)           
  16. org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)           
  17. javax.servlet.http.HttpServlet.service(HttpServlet.java:620)           
  18. org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)           
  19. javax.servlet.http.HttpServlet.service(HttpServlet.java:727)           
  20. org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)           
  21. org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)           
  22. org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)  
 
 
经过初步查看堆栈,大意是将JSP编译成Servlet产生了错误,类不匹配,怀疑可能是JSTL,Servlet和Tomcat版本产生了冲突。一番折腾,没有进展。
 
于是思考了一下,刚才只不过是添加了hadoop hdfs相关的jar包:
 
Xml代码   收藏代码
  1. <dependency>  
  2.     <groupId>org.apache.hadoop</groupId>  
  3.     <artifactId>hadoop-common</artifactId>  
  4.     <version>2.2.0</version>  
  5. </dependency>  
  6.   
  7. <dependency>  
  8.     <groupId>org.apache.hadoop</groupId>  
  9.     <artifactId>hadoop-hdfs</artifactId>  
  10.     <version>2.2.0</version>  
  11. </dependency>  
  12.   
  13. <dependency>  
  14.     <groupId>org.apache.hadoop</groupId>  
  15.     <artifactId>hadoop-auth</artifactId>  
  16.     <version>2.2.0</version>  
  17. </dependency>  
 
 
难道是其中包含了一些特殊的依赖?通过IntelliJ Idea中的pom编辑器,可以显示Maven Show Dependencies:
 


 
 
可以看出所有的依赖关系,果然,hadoop-common包依赖了servlet-api, jasper-runtime等可能与当前环境冲突的jar包,由于这些都是通过依赖关系链产生的关系,所以非常不容易被察觉。
 
同样,也可以通过mvn自带的工具在项目中命令行操作得到整个依赖的树形结构:
 
Java代码   收藏代码
  1. mvn dependency: tree   
  2.    
  3. [INFO] com.xxx:diablo-framework:war:1.0-SNAPSHOT  
  4. [INFO] +- javax.servlet:jstl:jar:1.2:compile  
  5. [INFO] +- javax:javaee-api:jar:6.0:provided  
  6. [INFO] +- log4j:log4j:jar:1.2.8:compile  
  7. [INFO] +- com.sun.mail:javax.mail:jar:1.5.2:compile  
  8. [INFO] |  \- javax.activation:activation:jar:1.1:compile  
  9. [INFO] +- commons-io:commons-io:jar:2.4:compile  
  10. [INFO] +- commons-beanutils:commons-beanutils:jar:1.9.2:compile  
  11. [INFO] |  +- commons-logging:commons-logging:jar:1.1.1:compile  
  12. [INFO] |  \- commons-collections:commons-collections:jar:3.2.1:compile  
  13. [INFO] +- commons-lang:commons-lang:jar:2.6:compile  
  14. [INFO] +- org.codehaus.jackson:jackson-xc:jar:1.9.13:compile  
  15. [INFO] |  \- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile  
  16. [INFO] +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile  
  17. [INFO] +- commons-httpclient:commons-httpclient:jar:3.1:test  
  18. [INFO] |  \- commons-codec:commons-codec:jar:1.2:compile  
  19. [INFO] +- junit:junit:jar:4.11:test  
  20. [INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test  
  21. [INFO] +- org.springframework:spring-core:jar:3.2.2.RELEASE:compile  
  22. [INFO] +- org.springframework:spring-aop:jar:3.2.2.RELEASE:compile  
  23. [INFO] |  \- aopalliance:aopalliance:jar:1.0:compile  
  24. [INFO] +- org.springframework:spring-aspects:jar:3.2.2.RELEASE:compile  
  25. [INFO] |  \- org.aspectj:aspectjweaver:jar:1.7.2:compile  
  26. [INFO] +- org.springframework:spring-beans:jar:3.2.2.RELEASE:compile  
  27. [INFO] +- org.springframework:spring-context:jar:3.2.2.RELEASE:compile  
  28. [INFO] +- org.springframework:spring-context-support:jar:3.2.2.RELEASE:compile  
  29. [INFO] +- org.springframework:spring-dao:jar:2.0.8:compile  
  30. [INFO] +- org.springframework:spring-expression:jar:3.2.2.RELEASE:compile  
  31. [INFO] +- org.springframework:spring-jdbc:jar:3.2.2.RELEASE:compile  
  32. [INFO] +- org.springframework:spring-jms:jar:3.2.2.RELEASE:compile  
  33. [INFO] +- org.springframework:spring-orm:jar:3.2.2.RELEASE:compile  
  34. [INFO] +- org.springframework:spring-oxm:jar:3.2.2.RELEASE:compile  
  35. [INFO] +- org.springframework:spring-test:jar:3.2.2.RELEASE:compile  
  36. [INFO] +- org.springframework:spring-tx:jar:3.2.2.RELEASE:compile  
  37. [INFO] +- org.springframework:spring-web:jar:3.2.2.RELEASE:compile  
  38. [INFO] +- org.springframework:spring-webmvc:jar:3.2.2.RELEASE:compile  
  39. [INFO] +- org.apache.commons:commons-exec:jar:1.3:compile  
  40. [INFO] +- commons-dbcp:commons-dbcp:jar:1.4:compile  
  41. [INFO] |  \- commons-pool:commons-pool:jar:1.5.4:compile  
  42. [INFO] +- org.hibernate:hibernate-core:jar:3.6.10.Final:compile  
  43. [INFO] |  +- antlr:antlr:jar:2.7.6:compile  
  44. [INFO] |  +- dom4j:dom4j:jar:1.6.1:compile  
  45. [INFO] |  +- org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final:compile  
  46. [INFO] |  +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile  
  47. [INFO] |  +- javax.transaction:jta:jar:1.1:compile  
  48. [INFO] |  \- org.slf4j:slf4j-api:jar:1.6.1:compile  
  49. [INFO] +- org.hibernate:hibernate-entitymanager:jar:3.6.10.Final:compile  
  50. [INFO] |  +- cglib:cglib:jar:2.2:compile  
  51. [INFO] |  |  \- asm:asm:jar:3.1:compile  
  52. [INFO] |  \- javassist:javassist:jar:3.12.0.GA:compile  
  53. [INFO] +- net.sf.ehcache:ehcache-core:jar:2.6.9:compile  
  54. [INFO] +- mysql:mysql-connector-java:jar:5.1.31:compile  
  55. [INFO] +- org.hsqldb:hsqldb:jar:2.2.9:compile  
  56. [INFO] +- commons-fileupload:commons-fileupload:jar:1.3.1:compile  
  57. [INFO] +- org.apache.poi:poi:jar:3.5-FINAL:compile  
  58. [INFO] +- org.apache.poi:poi-ooxml:jar:3.5-FINAL:compile  
  59. [INFO] |  \- org.apache.poi:ooxml-schemas:jar:1.0:compile  
  60. [INFO] |     \- org.apache.xmlbeans:xmlbeans:jar:2.3.0:compile  
  61. [INFO] |        \- stax:stax-api:jar:1.0.1:compile  
  62. [INFO] +- org.apache.oozie:oozie-client:jar:4.1.0:compile  
  63. [INFO] |  +- com.googlecode.json-simple:json-simple:jar:1.1:compile  
  64. [INFO] |  +- commons-cli:commons-cli:jar:1.2:compile  
  65. [INFO] |  +- com.google.guava:guava:jar:11.0.2:compile  
  66. [INFO] |  |  \- com.google.code.findbugs:jsr305:jar:1.3.9:compile  
  67. [INFO] |  +- org.apache.activemq:activemq-client:jar:5.8.0:compile  
  68. [INFO] |  |  +- org.apache.geronimo.specs:geronimo-jms_1.1_spec:jar:1.1.1:compile  
  69. [INFO] |  |  +- org.fusesource.hawtbuf:hawtbuf:jar:1.9:compile  
  70. [INFO] |  |  \- org.apache.geronimo.specs:geronimo-j2ee-management_1.1_spec:jar:1.0.1:compile  
  71. [INFO] |  +- org.slf4j:slf4j-simple:jar:1.6.6:compile  
  72. [INFO] |  \- xerces:xercesImpl:jar:2.10.0:compile  
  73. [INFO] |     \- xml-apis:xml-apis:jar:1.4.01:compile  
  74. [INFO] +- org.freemarker:freemarker:jar:2.3.20:compile  
  75. [INFO] +- org.apache.hadoop:hadoop-common:jar:2.2.0:compile  
  76. [INFO] |  +- org.apache.hadoop:hadoop-annotations:jar:2.2.0:compile  
  77. [INFO] |  +- org.apache.commons:commons-math:jar:2.1:compile  
  78. [INFO] |  +- xmlenc:xmlenc:jar:0.52:compile  
  79. [INFO] |  +- commons-net:commons-net:jar:3.1:compile  
  80. [INFO] |  +- org.mortbay.jetty:jetty:jar:6.1.26:compile  
  81. [INFO] |  +- org.mortbay.jetty:jetty-util:jar:6.1.26:compile  
  82. [INFO] |  +- com.sun.jersey:jersey-core:jar:1.9:compile  
  83. [INFO] |  +- com.sun.jersey:jersey-json:jar:1.9:compile  
  84. [INFO] |  |  +- org.codehaus.jettison:jettison:jar:1.1:compile  
  85. [INFO] |  |  +- com.sun.xml.bind:jaxb-impl:jar:2.2.3-1:compile  
  86. [INFO] |  |  |  \- javax.xml.bind:jaxb-api:jar:2.2.2:compile  
  87. [INFO] |  |  \- org.codehaus.jackson:jackson-jaxrs:jar:1.8.3:compile  
  88. [INFO] |  +- com.sun.jersey:jersey-server:jar:1.9:compile  
  89. [INFO] |  +- commons-el:commons-el:jar:1.0:compile  
  90. [INFO] |  +- net.java.dev.jets3t:jets3t:jar:0.6.1:compile  
  91. [INFO] |  +- commons-configuration:commons-configuration:jar:1.6:compile  
  92. [INFO] |  |  +- commons-digester:commons-digester:jar:1.8:compile  
  93. [INFO] |  |  \- commons-beanutils:commons-beanutils-core:jar:1.8.0:compile  
  94. [INFO] |  +- org.slf4j:slf4j-log4j12:jar:1.7.5:compile  
  95. [INFO] |  +- org.apache.avro:avro:jar:1.7.4:compile  
  96. [INFO] |  |  +- com.thoughtworks.paranamer:paranamer:jar:2.3:compile  
  97. [INFO] |  |  \- org.xerial.snappy:snappy-java:jar:1.0.4.1:compile  
  98. [INFO] |  +- com.google.protobuf:protobuf-java:jar:2.5.0:compile  
  99. [INFO] |  +- com.jcraft:jsch:jar:0.1.42:compile  
  100. [INFO] |  +- org.apache.zookeeper:zookeeper:jar:3.4.5:compile  
  101. [INFO] |  \- org.apache.commons:commons-compress:jar:1.4.1:compile  
  102. [INFO] |     \- org.tukaani:xz:jar:1.0:compile  
  103. [INFO] +- org.apache.hadoop:hadoop-hdfs:jar:2.2.0:compile  
  104. [INFO] |  +- commons-daemon:commons-daemon:jar:1.0.13:compile  
  105. [INFO] |  +- javax.servlet.jsp:jsp-api:jar:2.1:compile  
  106. [INFO] |  \- tomcat:jasper-runtime:jar:5.5.23:compile  
  107. [INFO] +- org.apache.hadoop:hadoop-auth:jar:2.2.0:compile  
  108. [INFO] +- com.xxx:diablo.communication:jar:1.0-SNAPSHOT:compile  
  109. [INFO] +- com.caucho:hessian:jar:3.1.5:compile  
  110. [INFO] \- org.quartz-scheduler:quartz:jar:1.8.4:compile  
 
 
于是,通过右键将这些jar包排除(Exclude)出去,最后编辑生成的依赖成为了这样:
 
Xml代码   收藏代码
  1. <dependency>  
  2.     <groupId>org.apache.hadoop</groupId>  
  3.     <artifactId>hadoop-common</artifactId>  
  4.     <version>2.2.0</version>  
  5.     <exclusions>  
  6.         <exclusion>  
  7.             <artifactId>servlet-api</artifactId>  
  8.             <groupId>javax.servlet</groupId>  
  9.         </exclusion>  
  10.         <exclusion>  
  11.             <artifactId>jasper-compiler</artifactId>  
  12.             <groupId>tomcat</groupId>  
  13.         </exclusion>  
  14.         <exclusion>  
  15.             <artifactId>jasper-runtime</artifactId>  
  16.             <groupId>tomcat</groupId>  
  17.         </exclusion>  
  18.         <exclusion>  
  19.             <artifactId>jsp-api</artifactId>  
  20.             <groupId>javax.servlet.jsp</groupId>  
  21.         </exclusion>  
  22.     </exclusions>  
  23. </dependency>  
  24.   
  25. <dependency>  
  26.     <groupId>org.apache.hadoop</groupId>  
  27.     <artifactId>hadoop-hdfs</artifactId>  
  28.     <version>2.2.0</version>  
  29.     <exclusions>  
  30.         <exclusion>  
  31.             <artifactId>servlet-api</artifactId>  
  32.             <groupId>javax.servlet</groupId>  
  33.         </exclusion>  
  34.     </exclusions>  
  35. </dependency>  
 
 
问题才得以解决,在普通的Java应用中,当出现相同版本的jar包,class时,是根据启动时的CLASSPATH先后顺序来决定最终使用的是哪个类型,但是这样就非常不确定。虽然OSGi技术可以通过隔离ClassLoader的方式解决这个问题,但OSGi本身稍显复杂臃肿,学习成本比较高,而且同样需要一个OSGi容器。这就要求我们在平时引入新的jar包时能够对其进行依赖分析,找出可能产生冲突的jar包,最终解决问题。
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值