2017-07-14 184 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 /文件夾中? –