2017-07-14 198 views
0

我写了一个Liferay模块并成功部署了它。在Gradle中增加了依赖项,Liferay说“未解决的需求:导入包”

然后我说这行build.gradledependencies部分:

compileOnly group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.3' 

运行./gradlew eclipse我可以使用该库在Eclipse中没有问题后。但部署失败:

12:29:35,454 WARN [fileinstall-/home/nico/liferay/osgi/modules][org_apache_felix_fileinstall:103] Error while starting bundle: file:/home/nico/liferay-dxp-digital-enterprise-7.0-sp3/osgi/modules/de.nico.mymodule-1.0.0.jar 
org.osgi.framework.BundleException: Could not resolve module: de.nico.mymodule [1085]_ Unresolved requirement: Import-Package: org.apache.http; version="4.5.3"_ [Sanitized] 
    at org.eclipse.osgi.container.Module.start(Module.java:429) 
    at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:402) 
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1253) 
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1225) 
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:512) 
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:361) 
    at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:312) 

我不知道为什么它正在寻找org.apache.http,而不是org.apache.httpcomponents

这里是我的bnd.bnd

Bundle-SymbolicName: de.nico.mymodule 
Bundle-Version: 1.0.0 
Liferay-Require-SchemaVersion: 1.0.0 

如何调查研究这个问题呢?
我不想手动下载/添加JAR。

回答

1

进一步调查将从例外消息开始。它说RUNTIME中不存在以下要求:

导入包:org.apache.http;版本=“4.5.3”

我假设它是下列之一:

  • 你没有部署httpcomponents(或者你需要一个版本..看到Semantic Versioning)库Liferay(作为编译工作,虽然部署失败)
  • httpcomponents可能不打包为OSGi包。在这种情况下,您必须决定如何使代码可用。有关更多信息,很好的出发点是the official docs(感谢安德烈,从注释推动这一)和David Nebinger's blog article

如何添加这些依赖于Liferay的运行是由你。如果依赖关系是OSGi捆绑包,则可以直接下载&进行部署。如果他们不是OSGi包,请遵循链接文章中描述的技术之一。

+1

还有一些关于它的官方文档:https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/adding-third-party-libraries-to-a-module –

+0

@ AndreaDiGiorgi:我尝试了该页面描述的内容,并在类型为org.gradle的对象上得到了'无法为参数[{group = org.apache.httpcomponents,name = httpclient,version = 4.5.3}]找到方法compileInclude .api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler' –

+0

@Olaf事实上,我没有“将httpcomponents部署到Liferay”,我正在考虑Gradle将正确的东西包含到我的模块中。我找到了https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient-osgi,你是否建议我手动下载它和它的许多依赖关系,并将它们全部放到Liferay的deploy /文件夹中? –