Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Use LiferayDataSource into Vaadin Portlet
Hello,
I would like to use the Liferay DataSource "jdbc/LiferayPool" into a Vaadin Portlet. So how can I gather it ?
Thank you very much,
Best regards,
There is nothing Vaadin specific about this.
If you are using Spring in your portlet, take a look e.g. at http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Database+Configuration.
You could also obtain the data source with InfrastructureUtil.getDataSource() or Liferay JNDIUtil, but both depend on portal-kernel.
Finally, you could use an approach like http://www.javapractices.com/topic/TopicAction.do?Id=127.
Sorry for my coming back. But I cannot reach the datasource.
When you say we could use JNDIUtil from Liferay, do you mean we need to include portal-kernal.jar into the external Vaadin Portlet ? Do you need other files ?
I am working with Tomcat-6.0.18
The following source codes is not good with my config :
Context initContext = new InitialContext();
DataSource ds = (DataSource)initContext.lookup("java:/comp/env/jdbc/ContactPool");
or :
Context initContext = new InitialContext();
Context envContext = initContex.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/ContactPool");
The datasource is declared into ROOT.xml as :
<Resource
name="jdbc/ContactPool"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://nmdevdb/lportal_523_v2?useUnicode=true&characterEncoding=UTF-8"
username="XXX"
password="XXX"
maxActive="20"
/>
In the META-INF/context.xml, I added an instruction as :
<ResourceLink global="jdbc/ContactPool" name="jdbc/ContactPool" type="javax.sql.DataSource"/>
If you have any ideas, it will be nice :-)
Thanks a lot.
Nicolas,
Nicolas Muller: Sorry for my coming back. But I cannot reach the datasource.
When you say we could use JNDIUtil from Liferay, do you mean we need to include portal-kernal.jar into the external Vaadin Portlet ? Do you need other files ?
Unfortunately, I am not an expert at this (not Vaadin specific at all) and don't have things set up for testing this quickly - I hope someone else can answer, or that you find the answer on some other forum.
If you do need to access the portal-kernel or certain other Liferay APIs, you should not deploy them yourself. Instead, you may need to add something like this to your context.xml:
<Context>
<Loader loaderClass="com.liferay.support.tomcat.loader.PortalClassLoader"/>
</Context>
Note that after this, you risk conflicts between your portlet and the portal as they are sharing the classloader.
I am not sure whether it is possible to refer to the JAR in liferay-plugin-package.properties instead of sharing the classloader or not.
You should also have the JAR in your development environment classpath (but not deploy it with the application).