2017-04-09 90 views
1

我正在使用Liferay DXP,並創建了一個服務構建器模塊。在這個模塊中,我必須使用「oracle.jdbc.driver.OracleDriver」類,因爲我開發了一個FinderImpl來添加一個方法。此方法調用一個數據庫中的過程,該數據庫不是Liferay的數據庫,我正在使用其他數據庫進行過程。如何在osgi中添加第三方依賴項Liferay DXP

我在lib/ext中有JDBC驅動程序(ojdbc7.jar)。

的的build.gradle文件是:

repositories { 
    mavenLocal() 
    mavenCentral() 
} 

dependencies { 
    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.6.0" 
    compileOnly project(":modules:test-manager:test-manager-api") 
    compileOnly group: "com.oracle", name: "ojdbc7", version: "12.1.0" 
} 

buildService { 
    apiDir = "../test--manager-api/src/main/java" 
    osgiModule = true 
    propsUtil = "com.test.manager.service.util.ServiceProps" 
} 

group = "com.test.manager" 

的bnd.bnd文件是:

Bundle-Name: test-manager-service 
Bundle-SymbolicName: com.test.manager.service 
Bundle-Version: 1.0.0 
Liferay-Require-SchemaVersion: 1.0.0 
Liferay-Service: true 

當我部署的模塊我得到這個錯誤:

Error while starting bundle: file:/C:/projects/test/modules/test-manager-service/test-manager-service-service/build/libs/com.test.manager.service-1.0.0.jar 
org.osgi.framework.BundleException: Could not resolve module: com.test.manager.service [536]_ Unresolved requirement: Import-Package: oracle.jdbc.driver_ [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) 

有人知道哪個是問題?以及如何在我的模塊中添加ojdbc7.jar以使用oracle.jdbc.driver.OracleDriver類?

非常感謝你提前! 帕特里夏

+0

由於Liferay論壇已經開始討論,請參閱https://meta.stackexchange.com/questions/141823/why-is-cross-posting-wrong-on-an-external-site並提供參考資料 –

回答

2

,而不是添加JDBC驅動程序lib/ext的,嘗試把它嵌入到你的模塊。您可以在模塊的bnd.bnd文件中添加諸如-includeresource: lib/ojdbc7.jar=ojdbc7-[0-9]*.jar;lib:=true之類的內容,或者按照these instructions

0

非常感謝您的回答!

我已經嘗試過但它不起作用。另外,我曾嘗試使用初始上下文實例來查找FinderImpl內部的JNDI資源,但我得到這個錯誤:

javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory cannot be found 

於是,我改變了類加載器和它的工作。該代碼是:

ClassLoader origLoader = Thread.currentThread().getContextClassLoader(); 
Thread.currentThread().setContextClassLoader(PortalClassLoaderUtil.getClassLoader()); 
InitialContext ctx = new InitialContext(); 
DataSource datasource = (DataSource) ctx.lookup("java:comp/env/jdbc/test1"); 
Connection connection = datasource.getConnection(); 
Thread.currentThread().setContextClassLoader(origLoader); 

我不喜歡這樣的代碼非常多,所以最後,我創建了一個帶有外部數據庫(https://web.liferay.com/es/web/user.26526/blog/-/blogs/liferay-7-service-builder-and-external-databases)服務建設者。

謝謝!

相關問題