Oracle 如何在osgi Liferay DXP中添加第三方依赖项

Oracle 如何在osgi Liferay DXP中添加第三方依赖项,oracle,jdbc,gradle,liferay,osgi,Oracle,Jdbc,Gradle,Liferay,Osgi,我正在使用Liferay DXP,并创建了一个service builder模块。在这个模块中,我必须使用“oracle.jdbc.driver.OracleDriver”类,因为为了添加方法,我开发了一个FinderImpl。此方法调用数据库中的一个过程,此数据库不是Liferay的数据库,我正在使用其他数据库进行此过程 我在lib/ext中有JDBC驱动程序(ojdbc7.jar) build.gradle文件是: repositories { mavenLocal() mave

我正在使用Liferay DXP,并创建了一个service builder模块。在这个模块中,我必须使用“oracle.jdbc.driver.OracleDriver”类,因为为了添加方法,我开发了一个FinderImpl。此方法调用数据库中的一个过程,此数据库不是Liferay的数据库,我正在使用其他数据库进行此过程

我在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)
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
有人知道问题出在哪里?我应该如何在模块中添加ojdbc7.jar以使用oracle.jdbc.driver.OracleDriver类

非常感谢您!,
Patricia

不要将JDBC驱动程序添加到
lib/ext
,而是尝试将其嵌入到您的模块中。您可以添加如下内容:lib/ojdbc7.jar=ojdbc7-[0-9]*.jar;lib:=true到模块的
bnd.bnd
文件,或遵循。

非常感谢您的回答

我试过了,但不起作用。此外,我还尝试使用初始上下文实例在FinderImpl中查找JNDI资源,但出现以下错误:

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)
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);
我不太喜欢这段代码,所以最后,我创建了一个带有外部数据库()的服务生成器


谢谢

由于Liferay论坛上的讨论已经开始,请查看并提供参考资料