views:

376

answers:

2

I'm deploying the most basic Portlet possible to Liferay:

public class FirstPortlet extends GenericPortlet
{
    @RenderMode(name="VIEW")
    public void welcomeWelcome(RenderRequest request, 
            RenderResponse response) throws  
            PortletException, IOException
    {       
        PrintWriter out = response.getWriter();
        out.println ("This is a portlet, <em>within a Portal</em>");
    }
}

On deployment, I'm getting a ClassCastException:

 Caused by: java.lang.ClassCastException: FirstPortlet cannot be cast to javax.po
rtlet.Portlet

After Googling, it appears that deploying portlet.jar is a mistake - I've made sure I'm not accidentally doing this.

javax.portlet.Portlet is implemented by GenericPortlet, and all Portlet examples seem to extend GenericPortlet so I assume that's ok.

Can anyone help?

+2  A: 

javax.portlet.Portlet is implemented by GenericPortlet, and all Portlet examples seem to extend GenericPortlet so I assume that's ok.

If GenericPortlet implements Portlet, my guess is that you have a class loader issue. The class is loaded twice, in two different class loaders and are by consequence considered different.

After Googling, it appears that deploying portlet.jar is a mistake - I've made sure I'm not accidentally doing this.

I would still suggest that you double check if you don't have portlet.jar (or another jar which contains Portlet) loaded twice somewhere. The possible locations depend on the container you are using (Tomcat? Glassfish? ).

ewernli
Excellent, thanks - I have to leave now but I'll check this as soon as I can. I'm sure it is indeed an extra portlet.jar. It's definitely not in my WAR file though.
Dick Chesterwood
Yes, it was Tomcat - see my reply to Jaromir, the portlet.jar was left behind in the tomcat/webapps directory.
Dick Chesterwood
+2  A: 

This is definitely classloading issue. If you are sure you don't have portlet.jar in your WAR archive you can turn on verbose classloading and watch where is the javax.portlet.Portlet loaded from.

To turn you verbose classloading pass following parameter to the JVM:

-verbose:class

Jaromir Hamala
Ouch. Yes, thanks for the information about verbose:class - that enabled me to find the answer.I suspect this is my own stupidity!I had deployed the portlet once including the portlet.jar file. Then I realized my mistake and removed it from all future deployments.I hadn't realized however that the jar file is still left behind in the tomcat /webapps directory.Fix: delete the appropriate folder from the webapps directory and redeploy again.
Dick Chesterwood