gpt4 book ai didi

maven - 传递依赖 : Using Elasticsearch Rest High Client problem in AEM

转载 作者:行者123 更新时间:2023-11-29 02:52:18 25 4
gpt4 key购买 nike

我正在尝试使用 Java High Level Rest ClientAdobe Experience Manager 中完成Lucene、Solr 和 Elasticsearch 搜索引擎之间的比较项目。

我在 elasticsearch 实现 方面遇到了一些问题。这是代码:

  • 父pom.xml中的依赖(核心pom.xml中定义相同)

    <!-- Elasticseach dependencies -->
    <dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>elasticsearch-rest-high-level-client</artifactId>
    <version>7.4.0</version>
    </dependency>
  • 我使用的唯一一行代码来自上面的依赖项

    try (RestHighLevelClient client = new 
    RestHighLevelClient(RestClient.builder(new HttpHost(server, port,
    protocol),
    new HttpHost(server, secondPort, protocol)));)
    {

    }
    catch (ElasticsearchException e)
    {
    LOG.error("Exception: " + e);
    }

protocol = "http", server = "localhost", port = 9200, secondPort = 9201

  • 错误

enter image description here

  • 来自 IntelliJ 的依赖

enter image description here

我知道依赖版本通常有问题,但在这种情况下都是 7.4.0。 elasticsearch 7.4.0v 也在 3 个节点上本地运行。

这个项目是在 We.Retail 项目上完成的,所以很容易复制。此外,所有出现此错误的代码都可在此处获得: https://github.com/tadijam64/search-engines-comparison-on-we-retail/tree/elasticsearch-integrationAEM 6.4v。

欢迎提供任何信息或想法。

更新我尝试添加以下内容以在外部嵌入这些依赖项,因为它们不是 OSGi 依赖项:

<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Embed-Dependency>org.apache.servicemix.bundles.solr-solrj, log4j, noggit, zookeeper,
elasticsearch-rest-high-level-client
</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Embed-Directory>OSGI-INF/lib</Embed-Directory>
<Export-Package>we.retail.core.model*</Export-Package>
<Import-Package>
*;resolution:=optional
</Import-Package>
<Private-Package>we.retail.core*</Private-Package>
<Sling-Model-Packages>
we.retail.core.model
</Sling-Model-Packages>
</instructions>
</configuration>
</plugin>
</plugins>
</build>

错误依然存在。我也尝试将它添加到“export-package”,但没有任何帮助。

然后 Elasticsearch documentation , 我需要使用 Elasticsearch 的是

<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.4.0</version>
</dependency>

但是 NoClassDefFoundErrors 发生了。这似乎是传递依赖性的问题。不确定,但任何想法都会受到赞赏。

其他一些建议可以在这里找到:https://forums.adobe.com/thread/2653586

我也尝试添加它的传递依赖项,如 org.elasticsearch 和 org.elasticsearch.client,但它不起作用。同样的错误,只是其他类。

AEM版本6.4,Java版本:jdk1.8.0_191.jdk

最佳答案

所以我的猜测是正确的,虽然<Embed-Transitive>true</Embed-Transitive> 没有包含传递依赖项|存在。

AEM 上将 elasticsearch 作为搜索引擎运行时需要以下问题:

  • 我在 pom.xml 中添加了所有传递依赖(版本在 parent/pom.xml 中定义):

      <!-- Elasticsearch -->
    <dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>elasticsearch-rest-high-level-client</artifactId>
    </dependency>
    <dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>elasticsearch-rest-client</artifactId>
    </dependency>
    <dependency>
    <groupId>org.elasticsearch</groupId>
    <artifactId>elasticsearch</artifactId>
    </dependency>
    <dependency>
    <groupId>org.elasticsearch</groupId>
    <artifactId>elasticsearch-x-content</artifactId>
    </dependency>
    <dependency>
    <groupId>org.elasticsearch.plugin</groupId>
    <artifactId>rank-eval-client</artifactId>
    </dependency>
    <dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-imaging</artifactId>
    <scope>test</scope>
    </dependency>
    <dependency>
    <groupId>org.elasticsearch.plugin</groupId>
    <artifactId>lang-mustache-client</artifactId>
    </dependency>
    <dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpasyncclient</artifactId>
    </dependency>

重要的是将所有第三方依赖项作为<Embed-Dependency>添加到ma​​ven-bundle-plugin中,如下所示:

    <plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Embed-Dependency>org.apache.servicemix.bundles.solr-solrj, noggit,
elasticsearch-rest-high-level-client,
elasticsearch,
elasticsearch-rest-client,
elasticsearch-x-content,
elasticsearch-core,
rank-eval-client,
lang-mustache-client,
httpasyncclient;
</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Embed-Directory>OSGI-INF/lib</Embed-Directory>
<Export-Package>we.retail.core.model*</Export-Package>
<Import-Package>
*;resolution:=optional
</Import-Package>
<Private-Package>
we.retail.core*
</Private-Package>
<Sling-Model-Packages>
we.retail.core.model
</Sling-Model-Packages>
<_fixupmessages>"Classes found in the wrong directory";is:=warning</_fixupmessages>
</instructions>
</configuration>
</plugin>

Important to notice:

  • All third-party dependencies (the ones outside of OSGi) must be included in the "Embed-Dependency"
  • "Embed-Transitive" must be set to true to include transitive dependencies
  • "Import-Package" must include "*;resolution:=optional" to exclude all dependencies that could not be resolved so that the program can runnormally
  • For some reason, there was an error in compile time when "elasticsearch" dependency was added which is not important for thistask, so I've decided to ignore it this way:
<_fixupmessages>"Classes found in the wrong directory";is:=warning</_fixupmessages>

尽管具有挑战性,但我终于解决了它。谷歌上有很多类似或相同的问题,所以我希望这对某人有所帮助。感谢所有试图提供帮助的人。

关于maven - 传递依赖 : Using Elasticsearch Rest High Client problem in AEM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58457282/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com