【问题标题】:Transitive Dependency: Using Elasticsearch Rest High Client problem in AEM传递依赖:在 AEM 中使用 Elasticsearch Rest High Client 问题
【发布时间】:2020-02-15 19:55:46
【问题描述】:

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

我在 elasticsearh 实施方面遇到了一些问题。 代码如下:

  • 父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

  • 错误

  • 来自 IntelliJ 的依赖项

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

这个项目是在 We.Retail 项目上完成的,因此很容易复制。此外,所有出现此错误的代码都可以在此处获得: https://github.com/tadijam64/search-engines-comparison-on-we-retail/tree/elasticsearch-integration AEM 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>

错误仍然存​​在。我也尝试将其添加到“导出包”中,但没有任何帮助。

通过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

【问题讨论】:

  • 在 AEM System Console 捆绑包中,您是否看到任何与弹性搜索相关的依赖项?
  • 仅在清单头和捆绑类路径下,也应该在其他地方吗?
  • 我认为清单会有一些导入条目等。实际的依赖关系不存在。我认为 AEM 不提供弹性搜索,这可能就是您收到 Class Not Found 异常的原因。依赖需要Embedded or separately installed as OSGi bundle
  • 试过了,手动安装了 ES rest 高级客户端和 org.elasticsearch 依赖项并添加为依赖项,但现在我有类似的:“java.lang.NoClassDefFoundError: org/elasticsearch/common/xcontent/DeprecationHandler "

标签: maven elasticsearch osgi aem elasticsearch-api


【解决方案1】:

所以我的猜测是正确的,虽然 &lt;Embed-Transitive&gt;true&lt;/Embed-Transitive&gt; 存在,但传递依赖并不包括在内。

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>
    

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

    <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>

重要提示:

  • 所有第三方依赖项(OSGi 之外的依赖项)都必须包含在“嵌入依赖项”中
  • “Embed-Transitive”必须设置为 true 才能包含传递依赖项
  • “Import-Package”必须包含“*;resolution:=optional”以排除所有无法解析的依赖项,以便程序可以运行 通常
  • 由于某种原因,在添加“elasticsearch”依赖项时编译时出错,对此并不重要 任务,所以我决定以这种方式忽略它:
<_fixupmessages>"Classes found in the wrong directory";is:=warning</_fixupmessages>

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

【讨论】:

    猜你喜欢
    • 2023-04-04
    • 2021-11-05
    • 2021-07-06
    • 2011-05-20
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多