2017-04-09 138 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)服务建设者。

谢谢!

相关问题