Why do I get a NoSuchMethodError on JodaTime.withYear()?

不打扰是莪最后的温柔 提交于 2019-11-28 01:24:39

WebLogic 10.3.6 includes this on the classpath:

joda.time_1.2.1.0.jar

This is earlier than the 1.3 that has the missing method.

Your code compiles, which is a good indication that your app's classpath has at least Joda 1.3.

Thus I suspect this is a WebLogic classpath issue. When your app uses libraries that are also on the WebLogic classpath, you need to tell WebLogic which library to use. You do this with the prefer-application-packages element in src/main/webapp/WEB-INF/weblogic.xml.

<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app
http://xmlns.oracle.com/weblogic/weblogic-web-app/1.3/weblogic-web-app.xsd">

  <context-root>myApp</context-root>
  <container-descriptor>
    <prefer-application-packages>
      <package-name>org.joda.time.*</package-name>
      <package-name>org.slf4j.*</package-name>
      <package-name>org.slf4j.impl.*</package-name>
      <package-name>org.slf4j.spi.*</package-name>
      <!-- others here -->
    </prefer-application-packages>
  </container-descriptor>

  <!-- rest of weblogic.xml here -->
</weblogic-web-app>

WebLogic has a classpath analysis tool called wls-cat to help locate these conflicts, described in this blog post. One caveat - do not just copy wls-cat's prefer-application-packages block into your webapp and think you're done - you need to resolve each conflict one by one. Sometimes that means excluding dependencies from your webapp or using scope provided.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!