Solution of jar package conflict in the integration of HBase and elasticsearch
Problem background
In the data platform, ES and HBase need to be used to build the data query interface for project construction. There is a bug of jar package conflict in the process of integration: com google. common. base. Stopwatch. ()V from class org. apache. hadoop. hbase. zookeeper. MetaTableLocator
terms of settlement
After investigation, it is confirmed that it is com google. Guava this package caused a conflict. Es depends on versions 18 and above, while HBase only supports versions 16 and above. The guava package has changed internally since 17, and the method has changed, so 18 is not downward compatible with version 16. During the project operation, if versions 16 and 18 are introduced at the same time, the calling process of ES and HBase will be confused. Then it's easy to do next. We can repackage, put guava 18 into es, and then display the package referring to guava 16 in the POM file. In this way, ES calls guava18, which is entered inside the package, while HBase calls guava16, which is external.
Repackage
Create a new Maven project and configure it in the POM file as follows:
Will go to www.org.org Joda and other four jar packages that may have conflicts are migrated through the Maven shade plugin plug-in and then re typed into a jar package, so that the jar package's own dependencies can be used instead of external dependencies when introducing the jar package. It should be noted here that you need to add com google. All four packages such as common will be migrated again, otherwise Java. Net will appear lang.IllegalAccessError: tried to access method com. google. common. Base error
Pack Project
The new dependency package will be in the In M2 Maven warehouse, if the company has built a warehouse, you need to upload the jar package. If you run the jar package directly, remember to recompile the project and replace the Lib directory
Project load new package
You only need to configure in the POM file:
In this way, guava18 package is in douguo shaded. Under elasticsearch, es will be called first. The externally configured guava16 will be called by HBase. The two versions of jar packages exist independently of each other!
Here, the problem is solved!
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.