将我的 liferay portlet 与 jdbc 驱动程序连接

Connect my liferay portlet with jdbc driver

我想将我的 portlet 连接到 postgresql。但是我的 portlet 没有看到 jdbc。在我的 portlet 包中,我有两个 类。 Connection.java 和 TestDBPortlet.java。 Connection.java 成功连接到 postgresql 但 TestDBPortlet.java 没有看到 jdbc。知道两者在同一个包中,它们必须具有相同的类,这是否正常?我在 tomcat/libs、tomcat/lib/ext 和 tomcat/webapps/root/web-inf/libs 中复制了 jbdc.jar,但没有任何变化。请帮助我!

您提到的目录不会使您的驱动程序对您的模块可见。

tomcat/libs, 
tomcat/lib/ext
tomcat/webapps/root/web-inf/libs

那些人不会为您的 portlet 提供 类,因为它在 OSGi 级别上提供了自己的 class-loader。您可以将 jar 文件嵌入到模块的 jar 中,也可以使用导出 OSGi 运行时所需包的驱动程序 jar。

要嵌入 jar,您可以使用模块的 bnd 文件,例如:

-includeresource: lib/javax.json.jar=javax.json-1.0.jar

Bundle-ClassPath: ., lib/javax.json.jar

但在这种情况下,您需要创建一个目录并将库放在那里。