java noSuchMethodError causes and solutions

file

java noSuchMethodError causes and solutions

Appearance reasons

A.class call B.methodX.

Run time loaded into the case of class B may be present in methodX

  • methodX approach does not exist

  • methodX A.class method signature and call B.methodX signatures do not match

root cause

Compile-time version B of inconsistencies and run-time version B

Run B in a jar with a plurality of classPath, loaded into the JVM error jar package

Different classLoader loaded to a different version B class.

ClassLoader child at the time when the parent class loader delegation, access to the B.class loaded into the parent classLoder

classification

jvm in class

  • the reason
  • Usually write code, compile time and jdk version used is relatively high, but time is running low jdk version used
  • solution
  • Confirm operating environment jdk version is correct

The company projects included in the category jar

  • the reason
  • The introduction of low version of the jar package

  • The introduction of the snapshot is not the latest version of the package

  • solution
  • Modified version of the jar package is dependent on the correct version

  • snapshot version of the package does not

  • Add -U parameter when executing mvn command. mvn clean package / install -U
  • not recommend

  • Other environmental compile time, too, to add parameters

  • Configuring maven

nexus

central

http://central

true

true

always

  • Not recommended for use

  • Other people should also be amended

  • Pom.xml in the project configuration
  • Recommended

Projects rely on third parties jar included in the category

  • the reason
  • The introduction of low version of the jar package

  • The introduction of more jar package, but is loaded into the wrong version of the jar package

  • Subclass classLoader load the class time, delegate to the parent class loader classLoader low version of classLoader

  • Targeting
  • 1. Begin by -verbose: class find loads to which class

  • 2. jvm class loader structure judgment, is that the class loader loads the class and then to find ways to solve

  • solution
  • Change to the correct version of the jar package

  • Choosing the right package through maven jar command

  • The first step: List dependent jar package
  • mvn dependency: list command lists all current dependent (including direct and transfer) list, and ranges.

  • mvn dependency: tree command lists all hierarchical dependence, dependence relationships can be seen from the book delivery.

  • Step Two: using exclude exclude undesirable dependence
  • Jvm using the View command to load the jar package which leads to errors
  • -verbose:class
Released two original articles · won praise 0 · Views 8

Guess you like

Origin blog.csdn.net/weixin_42335070/article/details/104946347