Search code examples
javajdbcliferayosgiliferay-7

Connect my liferay portlet with jdbc driver


I want to connect my portlet to postgresql. But my portlet does not see jdbc. In my portlet package I have two classes. Connection.java and TestDBPortlet.java. Connection.java successfully connects to postgresql but TestDBPortlet.java does not see jdbc. Is this normal knowing that both are in the same package, they must have the same classes? I have copy jbdc.jar in tomcat/libs, tomcat/lib/ext and tomcat/webapps/root/web-inf/libs but nothing changes. Help me please !


Solution

  • The directories you mentioned will not make your driver visible for your module.

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

    Those guys will not provide classes for your portlet as it has its own class-loader provided on the OSGi level. You can either embed the jar file inside the module's jar or use a driver jar that exports the packages you need on the OSGi runtime.

    To embed the jar you can use your module's bnd file, like in:

    -includeresource: lib/javax.json.jar=javax.json-1.0.jar
    
    Bundle-ClassPath: ., lib/javax.json.jar
    

    But in this case you will need to create a directory and put the lib there.