gpt4 book ai didi

elasticsearch - "Unresolved requirement: Import-Package"用于不在我的 build.gradle 中的模块

转载 作者:行者123 更新时间:2023-12-03 01:41:49 25 4
gpt4 key购买 nike

我想在 Liferay 7 SP4 FP30 模块中使用 Elasticsearch 的客户端 Java 类,所以我写了这个 build.gradle :

dependencies {
compileOnly group: "com.liferay", name: "com.liferay.portal.search.elasticsearch", version: "2.1.14"
compileOnly group: "com.liferay", name: "org.elasticsearch", version: "2.2.0.LIFERAY-PATCHED-1"

compileOnly group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "3.1.0"
compileOnly group: "com.liferay", name: "com.liferay.osgi.util", version: "3.0.0"
compileOnly group: "com.liferay", name: "com.liferay.portal.spring.extender", version: "2.0.0"
compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.0.0"
compileOnly group: "com.liferay", name: "com.liferay.portal.security.audit.api", version: "2.0.0"
compileOnly group: "com.liferay", name: "com.liferay.portal.configuration.metatype", version: "2.0.0"
compileOnly group: "org.osgi", name: "org.osgi.compendium", version: "5.0.0"
}

...和一个包含 import com.liferay.portal.search.elasticsearch.connection.ElasticsearchConnectionManager; 等代码的 Java 类和 Client client = elasticsearchConnectionManager.getClient();
它构建良好。

但是当我尝试启动模块时,会发生此错误:
org.osgi.framework.BundleException: Could not resolve module: mymodule [548]
Unresolved requirement: Import-Package: com.liferay.portal.search.elasticsearch.connection

为什么会这样?我的 build.gradle没有提到这个以 .connection 结尾的模块, 和 Maven does not seem to have any such module .

最佳答案

@gjoranv 是正确的,仅仅因为你在你的 gradle.build 上并不意味着它会在你的环境中。

首先,错误是由于缺少 Java 传统意义上的使用过的包。因此,您将需要一个以 jar 文件为代表的模块,以公开此包。

由于 liferay 在 Elastic Search 方面非常依赖于版本,并且依赖于意外版本,因此您可能会使用未公开的包并强制公开,通常通过 Uber 模块。

如果你觉得幸运,你也可以使用 compileInclude,而不是 compileOnly。以这种方式包含库可能会造成困惑,因为它会将 jar 嵌入到您的 jar 中并公开所有包。

另一种通常不太激进的可能性是嵌入 jar,并在包中设置类路径。为此,您只需将依赖项声明为 compile,然后在 bnd.bnd 文件中添加类路径。 (听起来比实际难,应该是一个微不足道的过程)

要记住的另一个问题是与您的 ElasticSearch 和 liferay 部署的对齐:2.2-2.4.x 但这只是因为如果您的对象被其他捆绑包使用或与老ES。

嵌入示例:

gradle.build

compile "org.apache.httpcomponents:httpclient"
compile "org.apache.httpcomponents:httpcore"

bnd.bnd
-includeresource: lib/httpclient.jar=httpclient-4.5.3.jar,\
lib/httpcore.jar=httpcore-4.4.6.jar

Bundle-ClassPath: ., lib/httpclient.jar, lib/httpcore.jar

关于elasticsearch - "Unresolved requirement: Import-Package"用于不在我的 build.gradle 中的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46945612/

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