简体   繁体   中英

Howto detect usage of missing symbol in Java classpath

I sometimes facing dependency hell in Java. It is common known problem: library A depends on library C in version 2.5 and library B depends on C too, but in version 2.6. Then I have to solve question: Are two versions of C library backward compatible? Can I use libraries A, B and C in one application classpath? Or should I create "shaded bundle" of A with old version of C?

If two versions of C library are incompatible and I use it, application can be started usually. But then after some hours or days can "no such method" exception occurs! I would like to detect this problem before application start, not in runtime.

Question is : Exist some tool that can list all used symbols in class and all provided symbols by class? Then I can create script that detect used but missing symbols...

The javap command can list all symbols defined by a class.

The javap -c command shows external methods and fields used by a class as comments in the disassembled bytecodes. You might be able to unpicked them.

One colleague suggest me migration manager ( https://www.lightbend.com/community/core-tools/migration-manager ), that shows binary incompatibility in classpath (two versions of one library). It isn't exactly what I wanted, but it helps a lot...

$java -jar migration-manager-cli-0.1.9.jar \
  --prev ~/.m2/repository/com/google/protobuf/protobuf-java/2.4.1/protobuf-java-2.4.1.jar  \
  --curr ~/.m2/repository/com/google/protobuf/protobuf-java/2.5.0/protobuf-java-2.5.0.jar \
  --direction both

Found 393 binary incompatibilities
==================================
 * abstract method getNameBytes()com.google.protobuf.ByteString in interface
   com.google.protobuf.DescriptorProtos#ServiceDescriptorProtoOrBuilder is
   present only in current version

...

Similar question being addressed here:

How to identify a missing method (Binary Compatibility) in a JAR statically

Quick googling revealed possible solution here:

http://vongosling.github.io/dependency-mediator/

(But I have no experience with the tool)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM