使用Maven在Java应用程序中运行两个版本的Elasticsearch [英] Run two versions of elasticsearch in java application using maven

查看:41
本文介绍了使用Maven在Java应用程序中运行两个版本的Elasticsearch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个遗留的整体应用程序,它使用elasticsearch 1.X,现在我们需要在同一应用程序中运行elasticsearch 7.X,以便在两个版本的Elasticsearch中都具有相同的应用程序索引和查询数据.

I have a legacy monolith application, which uses elasticsearch 1.X and now we need to run elasticsearch 7.X in the same application, so that same application index and query data in both version of elasticsearch.

在我的项目中,有多个模块,它们都有自己的POM和父POM,而我的使用Elasticsearch 7.X的新模块取决于使用1.X的某个模块.

In my project, there are multiple modules and they all have their own POM and parent POM, and my new module which uses elasticsearch 7.X depends on some module which uses 1.X.

尽管我在使用7.X的模块中排除了1.X的特定依赖性,但仍然在错误下方给出了我的答案:

Although I have excluded 1.X specific dependency in module which uses 7.X, Still it gives me below Error:

[76B7CCD2] java.lang.NoSuchFieldError:LATEST atorg.elasticsearch.Version.(Version.java:49)在org.elasticsearch.common.io.stream.StreamInput.(StreamInput.java:114)

[76B7CCD2] java.lang.NoSuchFieldError: LATEST at org.elasticsearch.Version.(Version.java:49) at org.elasticsearch.common.io.stream.StreamInput.(StreamInput.java:114)

经过大量研究并使用链接,如前所述,我排除了弹性1.x依赖项,但仍然看起来像我的其他子模块仍然具有ES 1.X,这也是必需的,因此因此,我的应用程序的整体类路径同时具有 org.elasticsearch.Version的两个版本来自同一包 org.elasticsearch 的java类,这是根本原因.

After doing a lot of research and using this and this link, As explained I excluded the elastic 1.x dependency but still looks like as my other sub-module still has ES 1.X and which is required as well, hence overall classpath of my application has both versions of org.elasticsearch.Version java class from the same package org.elasticsearch, which I feel is the root cause.

现在,如何从同一库的两个不同版本的同一包中包含同一类.

推荐答案

您不能.您只能使用一个给定的完整限定名称(包+名称)的类.

You can't. You can only have one class with a given full qualified name (package + name).

您可以尝试使用Maven阴影插件(实际上从未尝试过)对其中一个软件包进行着色(即重命名),这可能会起作用.

You can try to shade one of the packages (i.e. rename it) with the Maven shade plugin (never tried that, actually), which might work.

通常,您需要更改代码并四处弄弄,直到找到适用于所有依赖项的elasticsearch版本.

Usually, you need to change code and fiddle around until you find a version of elasticsearch that works with all dependencies.

这篇关于使用Maven在Java应用程序中运行两个版本的Elasticsearch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆