传递依赖性:在 AEM 中使用 Elasticsearch Rest High Client 问题
Transitive Dependency: Using Elasticsearch Rest High Client problem in AEM
我正在尝试使用 Adobe Experience Manager 中的 Java High Level Rest Client 来完成 Lucene、Solr 和 Elasticsearch 搜索引擎之间的比较项目.
我在使用 elasticsearch 实现 时遇到了一些问题。
这是代码:
parent中的依赖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>
错误依旧。我也尝试将它添加到 "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,但它不起作用。同样的错误,只是其他 class.
AEM 版本 6.4,Java 版本:jdk1.8.0_191.jdk
所以我的猜测是正确的,虽然 <Embed-Transitive>true</Embed-Transitive>
存在但不包括传递依赖项。
当运行elasticsearch作为搜索引擎在AEM上时需要以下问题:
我在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>在maven-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 run
normally
- For some reason, there was an error in compile time when "elasticsearch" dependency was added which is not important for this
task, so I've decided to ignore it this way:
<_fixupmessages>"Classes found in the wrong directory";is:=warning</_fixupmessages>
虽然困难重重,但我终于解决了。 Google上有很多相似或相同的问题,所以我希望这对某人有所帮助。感谢所有试图提供帮助的人。
我正在尝试使用 Adobe Experience Manager 中的 Java High Level Rest Client 来完成 Lucene、Solr 和 Elasticsearch 搜索引擎之间的比较项目.
我在使用 elasticsearch 实现 时遇到了一些问题。 这是代码:
parent中的依赖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>
错误依旧。我也尝试将它添加到 "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,但它不起作用。同样的错误,只是其他 class.
AEM 版本 6.4,Java 版本:jdk1.8.0_191.jdk
所以我的猜测是正确的,虽然 <Embed-Transitive>true</Embed-Transitive>
存在但不包括传递依赖项。
当运行elasticsearch作为搜索引擎在AEM上时需要以下问题:
我在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>在maven-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 run normally
- For some reason, there was an error in compile time when "elasticsearch" dependency was added which is not important for this task, so I've decided to ignore it this way:
<_fixupmessages>"Classes found in the wrong directory";is:=warning</_fixupmessages>
虽然困难重重,但我终于解决了。 Google上有很多相似或相同的问题,所以我希望这对某人有所帮助。感谢所有试图提供帮助的人。