简体   繁体   English

将简单的Portlet部署到Liferay-ClassCastException

[英]Deploying a simple Portlet to Liferay - ClassCastException

I'm deploying the most basic Portlet possible to Liferay: 我正在将最基本的Portlet部署到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: 部署时,我收到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. 谷歌搜索之后,部署portlet.jar似乎是一个错误-我确保我不会意外地这样做。

javax.portlet.Portlet is implemented by GenericPortlet, and all Portlet examples seem to extend GenericPortlet so I assume that's ok. javax.portlet.Portlet由GenericPortlet实现,所有Portlet示例似乎都扩展了GenericPortlet,因此我认为可以。

Can anyone help? 有人可以帮忙吗?

javax.portlet.Portlet is implemented by GenericPortlet, and all Portlet examples seem to extend GenericPortlet so I assume that's ok. javax.portlet.Portlet由GenericPortlet实现,所有Portlet示例似乎都扩展了GenericPortlet,因此我认为可以。

If GenericPortlet implements Portlet , my guess is that you have a class loader issue. 如果GenericPortlet实现Portlet ,我的猜测是您遇到了类加载器问题。 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. 谷歌搜索之后,部署portlet.jar似乎是一个错误-我确保我不会意外地这样做。

I would still suggest that you double check if you don't have portlet.jar (or another jar which contains Portlet ) loaded twice somewhere. 我仍然建议您仔细检查一下是否没有在某处两次加载portlet.jar (或另一个包含Portlet jar)。 The possible locations depend on the container you are using (Tomcat? Glassfish? ). 可能的位置取决于您使用的容器(Tomcat?Glassfish?)。

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. 如果确定您的WAR档案中没有portlet.jar,则可以打开详细的类加载,并查看从何处加载javax.portlet.Portlet。

To turn you verbose classloading pass following parameter to the JVM: 要使您冗长的类加载,请将以下参数传递给JVM:

-verbose:class -verbose:class

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM