Liferay - ...ApplicationPortlet2 cannot be cast to ...Portlet

Here’s the situation:
I got a 6.0.6 liferay portal bundled with Tomcat installation.
I replaced the liferay internal vaadin.jar with the 6.7.1 version of vaadin (renaming the vaadin-6.7.1.jar to ‘vaadin.jar’)
I have multiple working regularly created “vaadin project - portlet2” applications that run simultaneously on this liferay server. So I’m rather sure that part of my setup is working just fine.

Next up I create a maven-web-project.
In this project I add the portlet description xml’s so that I can create my own vaading portlet that is mavenized.
I add a dependency on the vaadin-6.7.1 jar through Maven.
I develop my stuff, it all seems to work fine. I can get the build working, the tests run, the jetty test work, basically all seems fine.

I then copy the war created into my deploy folder in Tomcat and…

08:11:39,536 ERROR [HotDeployUtil:112]
 com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering portlets for Dante-web
com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering portlets for Dante-web
	at com.liferay.portal.kernel.deploy.hot.BaseHotDeployListener.throwHotDeployException(BaseHotDeployListener.java:45)
	at com.liferay.portal.deploy.hot.PortletHotDeployListener.invokeDeploy(PortletHotDeployListener.java:104)
	at com.liferay.portal.kernel.deploy.hot.HotDeployUtil._doFireDeployEvent(HotDeployUtil.java:109)
	at com.liferay.portal.kernel.deploy.hot.HotDeployUtil._fireDeployEvent(HotDeployUtil.java:182)
	at com.liferay.portal.kernel.deploy.hot.HotDeployUtil.fireDeployEvent(HotDeployUtil.java:38)
	at com.liferay.portal.kernel.servlet.PortletContextListener.doPortalInit(PortletContextListener.java:99)
	at com.liferay.portal.kernel.util.BasePortalLifecycle.portalInit(BasePortalLifecycle.java:42)
	at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:52)
	at com.liferay.portal.kernel.util.BasePortalLifecycle.registerPortalLifecycle(BasePortalLifecycle.java:50)
	at com.liferay.portal.kernel.servlet.PortletContextListener.contextInitialized(PortletContextListener.java:55)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
	at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1244)
	at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1342)
	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:303)
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
	at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1337)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
	at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
	at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassCastException: com.vaadin.terminal.gwt.server.ApplicationPortlet2 cannot be cast to javax.portlet.Portlet
	at com.liferay.portlet.PortletBagFactory.create(PortletBagFactory.java:123)
	at com.liferay.portal.deploy.hot.PortletHotDeployListener.initPortlet(PortletHotDeployListener.java:456)
	at com.liferay.portal.deploy.hot.PortletHotDeployListener.doInvokeDeploy(PortletHotDeployListener.java:253)
	at com.liferay.portal.deploy.hot.PortletHotDeployListener.invokeDeploy(PortletHotDeployListener.java:101)
	... 19 more

as I understand from several google tries, the problem resides in two different versions of vaadin being loaded by my JVM.

Stuff I have tried:

  • remove maven dependency on vaadin & add the jar as an external jar → compile error
  • tried changing scope of the vaadin dependency to ‘provided’

So, anyone who can help me out with this?

To be complete with the case description:

1/ the maven-web-project is part of a multi-module maven project.

2/ I have tried & succeeded in creating a maven-vaadin-application project and rework it to a portlet application that is working fine on my liferay installation.

3/ I am willing and able to provide the source code/project directory of the entire maven project (the parent & 3 child projects that is).

4/ the relevant xml descriptors:



pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<name>Dante web application</name>
	<groupId>nl.ou.dante</groupId>
	<artifactId>Dante-web</artifactId>
	<version>1.0</version>
	<packaging>war</packaging>
 
	<parent>
		<artifactId>Dante</artifactId>
		<groupId>nl.ou.dante</groupId>
		<version>1.0</version>
	</parent>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <vaadin.version>6.7.1</vaadin.version> <!-- Liferay 6.0.6 has vaadin 6.4.10 build-in > I replaced the local vaadin.jar with the 6.7.1 -->
        <gwt.version>2.3.0</gwt.version>
        <gwt.plugin.version>2.2.0</gwt.plugin.version>
	</properties>
    
    <build>
		<finalName>Dante-web</finalName>
		
		<resources>
            <resource>
                <filtering>true</filtering>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
        
        <testResources>
            <testResource>
                <filtering>true</filtering>
                <directory>src/test/resources</directory>
            </testResource>
        </testResources>
		
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>1.6</source>
					<target>1.6</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
    

	<dependencies>
		<dependency>
			<groupId>nl.ou.dante</groupId>
			<artifactId>Dante-app</artifactId>
			<version>1.0</version>
		</dependency>
		<dependency>
			<groupId>com.vaadin</groupId>
			<artifactId>vaadin</artifactId>
			<version>6.7.1</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-portlet</artifactId>
			<version>2.0.8</version>
		</dependency>
		<dependency>
			<groupId>javax.portlet</groupId>
			<artifactId>portlet-api</artifactId>
			<version>2.0</version>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<version>3.0.1</version>
		</dependency>
	</dependencies>
</project>



liferay-display.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE display PUBLIC "-//Liferay//DTD Display 4.0.0//EN" "http://www.liferay.com/dtd/liferay-display_4_0_0.dtd">
<display>
    <category name="Vaadin">
        <portlet id="Dante portlet"/>
    </category>
</display>



liferay-plugin-package.properties

name=Dante portlet
short-description=Dante
module-group-id=Vaadin
module-incremental-version=1
#change-log=
#page-uri=
#author=
license=Proprietary
portal-dependency-jars=\
    vaadin.jar



liferay-portlet.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 4.3.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_4_3_0.dtd">
<liferay-portlet-app>
    <portlet>
        <!-- Matches definition in portlet.xml. -->
        <!-- Note: Must not be the same as servlet name. -->
        <portlet-name>Dante portlet</portlet-name>
        <instanceable>true</instanceable>
        <ajaxable>false</ajaxable>
    </portlet>
</liferay-portlet-app>



portlet.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"
	xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd 
						http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">

	<portlet>
		<portlet-name>Dante portlet</portlet-name>
		<display-name>Dante</display-name>

		<portlet-class>com.vaadin.terminal.gwt.server.ApplicationPortlet2</portlet-class>
		<init-param>
			<name>application</name>
			<value>nl.ou.dante.ui.Dante</value>
		</init-param>

		<init-param>
			<name>style</name>
			<value>width:846px; height:600px; padding: 0px 0px 0px 0px</value>
		</init-param>

		<!-- To enable displaying multiple Vaadin portlets on a page, they should 
			all use the same widgetset. In that case, the widgetset can be configured 
			on the portal level (parameter vaadin.widgetset) or here for each portlet. -->
		<!-- <init-param> <name>widgetset</name> <value>com.vaadin.portal.gwt.PortalDefaultWidgetSet</value> 
			</init-param> -->

		<!-- Supported portlet modes and content types. -->
		<supports>
			<mime-type>text/html</mime-type>
			<portlet-mode>view</portlet-mode>
			<!-- <portlet-mode>edit</portlet-mode> -->
			<!-- <portlet-mode>help</portlet-mode> -->
		</supports>

		<!-- Not always required but Liferay uses these. -->
		<portlet-info>
			<title>DAnTE - Aanmelden voor Tentamen</title>
			<short-title>Dante</short-title>
		</portlet-info>
	</portlet>
</portlet-app>



web.xml

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	version="2.4"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	<display-name>Dante</display-name>
	<context-param>
		<description>Vaadin production mode</description>
		<param-name>productionMode</param-name>
		<param-value>false</param-value>
	</context-param>

	<servlet>
		<servlet-name>DanteServlet</servlet-name>
		<servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
		<init-param>
			<description>Vaadin application class to start</description>
			<param-name>application</param-name>
			<param-value>***.***.***.Dante</param-value>
		</init-param>
	</servlet>
	<servlet-mapping>
        <servlet-name>DanteServlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath*:applicationContext.xml</param-value>
	</context-param>

	<context-param>
		<param-name>log4jConfigLocation</param-name>
		<param-value>classpath:log4j.properties</param-value>
	</context-param>

	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<listener>
		<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
	</listener>
</web-app>

This is a bit old post, but…

The problem is probably caused by a portlet.jar in the WEB-INF/lib in the WAR. it should not be there as it conflicts with the built-in library in the portal. If you need it while compiling your project, you should have it in a separate lib directory that is not included in the WAR.

Note: if you remove the portlet.jar from the project, you should also remove it from webapps/yourproject/WEB-INF/lib/portlet.jar as Tomcat doesn’t remove the file when redeploying. Better yet, delete the entire webapps/yourproject before redeploying.