[Java][Liferay] 解决Liferay ext项目deploy的问题

Liferay ext project在install war包之后需要重启服务器,重启服务器中会执行ExtHotDeployListener中的逻辑,这里有一个坑,如果是第二次以后install ext war包,会发现新修改的文件不起作用,原因如下

ExtHotDeployListener.java

    protected void doInvokeDeploy(HotDeployEvent hotDeployEvent)
        throws Exception {

        ServletContext servletContext = hotDeployEvent.getServletContext();

        String servletContextName = servletContext.getServletContextName();

        if (_log.isDebugEnabled()) {
            _log.debug("Invoking deploy for " + servletContextName);
        }

        String xml = HttpUtil.URLtoString(
            servletContext.getResource(
                "/WEB-INF/ext-" + servletContextName + ".xml"));

        if (xml == null) {
            return;
        }

        if (_log.isInfoEnabled()) {
            _log.info(
                "Registering extension environment for " + servletContextName);
        }

        /*
        * Ext 项目在重启tomcat的时候会checkd liferay-portal/tomcat-xxx/webapps/ROOT/WEB-INF/ext-project-***-ext.xml是否存在
        * 如果存在,就不执行后面的逻辑,也就不会执行installExt(***),那么也不会重新拷贝替换的文件
        *
        */
        if (ExtRegistry.isRegistered(servletContextName)) {
            if (_log.isInfoEnabled()) {
                _log.info(
                    "Extension environment for " + servletContextName +
                        " has been applied.");
            }

            return;
        }

        Map<String, Set<String>> conflicts = ExtRegistry.getConflicts(
            servletContext);

        if (!conflicts.isEmpty()) {
            StringBundler sb = new StringBundler();

            sb.append(
                "Extension environment for " + servletContextName +
                    " cannot be applied because of detected conflicts:");

            for (Map.Entry<String, Set<String>> entry : conflicts.entrySet()) {
                String conflictServletContextName = entry.getKey();
                Set<String> conflictFiles = entry.getValue();

                sb.append("\n\t");
                sb.append(conflictServletContextName);
                sb.append(":");

                for (String conflictFile : conflictFiles) {
                    sb.append("\n\t\t");
                    sb.append(conflictFile);
                }
            }

            _log.error(sb.toString());

            return;
        }

        installExt(servletContext, hotDeployEvent.getContextClassLoader());

        FileAvailabilityUtil.reset();

        if (_log.isInfoEnabled()) {
            _log.info(
                "Extension environment for " + servletContextName +
                    " has been applied. You must reboot the server and " +
                        "redeploy all other plugins.");
        }
    }
xxx-ext.xml格式如下

<ext-info>
    <servlet-context-name>hsf-plugins-shared-ext</servlet-context-name>
    <files>
        <file>xxxx-ext.xml</file>
        <file>ext-impl/classes/com/liferay/portal/action/xxx.class</file>
                ....
        <file>ext-web/docroot/html/js/xxx.js</file>
        <file>web.xml</file>
    </files>
</ext-info>
解决方案

1>. 去除掉doInvokeDeploy中这段逻辑,不管是否包含ext-project-***-ext.xml都执行install


if (ExtRegistry.isRegistered(servletContextName)) {
    if (_log.isInfoEnabled()) {
        _log.info(
            "Extension environment for " + servletContextName +
                " has been applied.");
    }

    return;
}

2>. 在第二次install ext project war包之后需要删除liferay-portal/tomcat-xxx/webapps/ROOT/WEB-INF/ext-project-***-ext.xml,然后重启tomcat

转载于:https://www.cnblogs.com/chenyongblog/p/5831685.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值