[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