Uploaded image for project: 'Felix'
  1. Felix
  2. FELIX-6198

Problem with embeding elasticsearch dependency

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • maven-bundle-plugin-4.2.1
    • None
    • Maven Bundle Plugin
    • Adobe Experience Manager 6.4, Java 1.8 (tried on 9 and 11 as well), elasticsearch version 7.4.1
    • Important

    Description

      I am trying to embed the following dependency and it's transitive dependencies:

       

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

       

      I am working with AEM 6.4v and tried maven-bundle-plugin versions 2.1.0 and 4.2.1.

      With first version, I can not build project due to the following error:
       Classes found in the wrong directory: elasticsearch/META-INF/versions/9/org/elasticsearch/monitor/jvm
      I've also tried two options of maven-bundle plugin which are showed bellow:

      With maven hade plugin:

       

      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-shade-plugin</artifactId>
          <version>1.1</version>
          <executions>
              <execution>
                  <phase>package</phase>
                  <goals>
                      <goal>shade</goal>
                  </goals>
                  <configuration>
                      <artifactSet>
                          <includes>
                              <include>org.elasticsearch.client:elasticsearch-rest-high-level-client</include>
                              <include>org.elasticsearch:elasticsearch</include>
                              <include>org.elasticsearch.client:elasticsearch-rest-client</include>
                          </includes>
                      </artifactSet>
                      <filters>
                          <filter>
                              <artifact>org.elasticsearch.client:elasticsearch-rest-high-level-client</artifact>
                              <excludes>
                                  <exclude>**</exclude>
                              </excludes>
                          </filter>
                          <filter>
                              <artifact>org.elasticsearch:elasticsearch</artifact>
                              <excludes>
                                  <exclude>**</exclude>
                              </excludes>
                          </filter>
                          <filter>
                              <artifact>org.elasticsearch.client:elasticsearch-rest-client</artifact>
                              <excludes>
                                  <exclude>**</exclude>
                              </excludes>
                          </filter>
                      </filters>
                      <promoteTransitiveDependencies>true</promoteTransitiveDependencies>
                      <createDependencyReducedPom>true</createDependencyReducedPom>
                  </configuration>
              </execution>
          </executions>
      </plugin>
      <plugin>
          <groupId>org.apache.felix</groupId>
          <artifactId>maven-bundle-plugin</artifactId>
          <version>4.2.1</version>
          <extensions>true</extensions>
          <configuration>
              <instructions>
                  <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                  <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>
                  <!--<_versionpolicy>[$(version;==;$(@)),$(version;+;$(@)))</_versionpolicy>-->
                  <_removeheaders>Ignore-Package,Include-Resource,Private-Package,Embed-Dependency</_removeheaders>
              </instructions>
              <unpackBundle>true</unpackBundle>
          </configuration>
      </plugin>

       

      Second without maven shade 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*, rank-eval-client, lang-mustache-client,
                       httpasyncclient, mapper-extras-client, parent-join-client,
                       aggs-matrix-stats-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>
       <plugin>
           <groupId>org.apache.maven.plugins</groupId>
           <artifactId>maven-javadoc-plugin</artifactId>
           <configuration>
               <excludePackageNames>
                   *.impl
               </excludePackageNames>
           </configuration>
       </plugin>
      

      Dependencies:

      <!-- Elasticsearch -->
      <dependency>
          <groupId>org.elasticsearch.client</groupId>
          <artifactId>elasticsearch-rest-high-level-client</artifactId>
          <version>7.4.1</version>
      </dependency>
      <dependency>
          <groupId>org.elasticsearch</groupId>
          <artifactId>elasticsearch</artifactId>
          <version>7.4.1</version>
      </dependency>
      <dependency>
          <groupId>org.elasticsearch.client</groupId>
          <artifactId>elasticsearch-rest-client</artifactId>
          <version>7.4.1</version>
      </dependency>
      

      Also I got this warning all the time in IntelliJ - The package org.elasticsearch.client is inside a non-bundle dependency on this code:

      try (RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(new HttpHost(server, port, protocol),//
      new HttpHost(server, secondPort, protocol))); ResourceResolver resourceResolver = request.getResourceResolver())
      {
      if (indexType.equalsIgnoreCase(PROP_INDEX_TYPE_INDEX))
      {
      Session session = resourceResolver.adaptTo(Session.class);
      XContentBuilder builder = this.elasticsearchService.crawlContent(session);

      IndexRequest indexRequest = new IndexRequest(indexName);
      indexRequest.id("2");
      try

      { indexRequest.source(builder); IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT); writeResponse(indexResponse, response); }

       

      So problem is sometimes shown as NoClassDefinition for come of transitive dependencies, and sometimes servlet returns 500 error if any of elasticsearch imports are inside the code. 

      Any idea/help will be appreciated.

      Whis is done on [we.retail|https://github.com/Adobe-Marketing-Cloud/aem-sample-we-retail] project so it is easy replicable. You can see full code on the following links:

      https://github.com/tadijam64/search-engines-comparison-on-we-retail/blob/elasticsearch-servlet-impl/core/pom.xml

       

      and other version here:

      https://github.com/tadijam64/search-engines-comparison-on-we-retail/blob/elasticsearch-maven-shade-test/core/pom.xml

       

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            tadijam Tadija
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: