【问题标题】:Liferay portlet deployment Java ErrorLiferay Portlet 部署 Java 错误
【发布时间】:2015-09-03 08:41:58
【问题描述】:

我在尝试在 Liferay 6.2 中部署 portlet 时遇到问题。我真的是 JAVA 的新手,而且还处理这种错误,所以如果我在处理这些问题时有点天真,请原谅我。

这些是我在 Eclipse 上遇到的错误:

找不到“http://java.sun.com/portlet”的标签库描述符,关于这一行:

<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>

我还收到一条关于此行的警报:“未知标记 (portlet:defineObjects)”:

<portlet:defineObjects />

最后这个错误“在这一行找到多个注释:locale 无法解析为变量,portletConfig 无法解析”关于这一行:

ResourceBundle resourceBundle = portletConfig.getResourceBundle(locale);

这是我的 init.jsp(请在最后阅读我的笔记):

<%@ page pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %>

<%@ taglib uri="/WEB-INF/tld/c-rt.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt"%>
<%@ taglib uri="/WEB-INF/tld/fn.tld" prefix="fn"%>

<%@ page isELIgnored ="false" %> 

<%@ page import="java.util.ResourceBundle" %>
<%@ page import="java.util.Locale" %>
<%@ page import="java.util.Enumeration" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.List" %>

<%@ page import="java.text.SimpleDateFormat"%>

<%@ page import="javax.portlet.PortletSession"%>

<%@ page import="com.liferay.portal.kernel.dao.orm.QueryUtil"%>
<%@ page import="com.liferay.portal.kernel.util.ParamUtil"%>
<%@ page import="com.liferay.portal.kernel.util.LocaleUtil"%>

<%@ page import="net.opentrends.caoc.portlet.valisa.util.*"%>
<%@ page import="net.opentrends.caoc.portlet.valisa.model.*"%>
<%@ page import="net.opentrends.caoc.portlet.valisa.support.model.*" %>
<%@ page import="net.opentrends.caoc.portlet.valisa.portlet.missatges.*"%>

<liferay-theme:defineObjects />
<portlet:defineObjects />

<%
ResourceBundle resourceBundle = portletConfig.getResourceBundle(locale);
PropsUtil mailProperties = PropsUtil.getInstance("/email.properties");
int maxFileSize = Integer.valueOf(mailProperties.getProperty("email.valisa.maxAttachmentSize"));
String maxFileSizeText = mailProperties.getProperty("email.valisa.maxAttachmentSize.text");
int maxTotalFilesSize = Integer.valueOf(mailProperties.getProperty("email.valisa.maxTotalAttachmentSize"));
String maxTotalFilesSizeText = mailProperties.getProperty("email.valisa.maxTotalAttachmentSize.text");
%>
<script type="text/javascript">
<!--
// Variables
var midaMaximaAnnex = <%= maxFileSize %>;
var midaMaximaAnnexText = '<%= maxFileSizeText %>';
var midaMaximaTotalAnnexos = <%= maxTotalFilesSize %>;
var missatgeErrorMidaMaximaCarregantAnnex = "No es pot carregar el document annex: la mida màxima admesa és de "+midaMaximaAnnexText + " per document.";
var midaMaximaTotalAnnexosText = '<%= maxTotalFilesSizeText %>';
var missatgeInfoMidaMaximaAnnexPermesa = "<p>Atenció, tingui en compte que en cas que els annexos superin la mida de  " + midaMaximaAnnexText + ", només s'enviarà el justificant com a annex del correu-e</p>";
var missatgeAlertaMidaMaximaTotalAnnexosSuperada = "<p>El document o documents annexos no s'enviaran perquè superen els " + midaMaximaTotalAnnexosText + " (màx. autoritzat)</p>";
var missatgeErrorMidaMaximaCarregantTotsAnnexos = "No es pot carregar el document annex: s'ha arribat al màxim de " + midaMaximaTotalAnnexosText + " permesos com a màxim per a tots els documents adjunts.";
var valisaContexte = "${pageContext.request.contextPath}";
//-->
</script>

<c:set var="usuari" value="${sessionScope.VALISA_USER_BEAN }"/>
<c:set var="menu" value="${sessionScope.VALISA_MENU_BEAN }"/>

<portlet:actionURL var="processActionURL" />

<portlet:actionURL var="ajaxProcessActionURL" windowState="exclusive" />

<portlet:actionURL var="safataEntradaURL">
    <portlet:param name="<%=WebKeys.VALISA_CMD%>" value="<%= WebKeys.VALISA_CMD_SAFATA_ENTRADA %>" />
</portlet:actionURL>

<portlet:actionURL var="safataHistoricEntradaURL">
    <portlet:param name="<%=WebKeys.VALISA_CMD%>" value="<%= WebKeys.VALISA_CMD_SAFATA_HISTORIC_ENTRADA %>" />
</portlet:actionURL>

<portlet:actionURL var="safataEnviadesURL">
    <portlet:param name="<%=WebKeys.VALISA_CMD%>" value="<%= WebKeys.VALISA_CMD_SAFATA_ENVIADES %>" />
</portlet:actionURL>

<portlet:actionURL var="safataHistoricEnviadesURL">
    <portlet:param name="<%=WebKeys.VALISA_CMD%>" value="<%= WebKeys.VALISA_CMD_SAFATA_HISTORIC_ENVIADES %>" />
</portlet:actionURL>

<portlet:actionURL var="safataNoLlegidesEnTerminiURL">
    <portlet:param name="<%=WebKeys.VALISA_CMD%>" value="<%= WebKeys.VALISA_CMD_SAFATA_NO_LLEGIDES_TERMINI %>" />
</portlet:actionURL>

<portlet:actionURL var="safataEsborranysURL">
    <portlet:param name="<%=WebKeys.VALISA_CMD%>" value="<%= WebKeys.VALISA_CMD_SAFATA_ESBORRANYS %>" />
</portlet:actionURL>

<portlet:actionURL var="safataVistiplausURL">
    <portlet:param name="<%=WebKeys.VALISA_CMD%>" value="<%= WebKeys.VALISA_CMD_SAFATA_VISTIPLAUS %>" />
</portlet:actionURL>

我知道我遇到的很多错误都与缺少一些所需的 tlds 有关,我试图将这些 tlds 添加到我的 webinf/tld 文件夹中,但从那时起我开始在控制台上收到奇怪的错误消息,并且看不到我的 portlet 工作(Portlet 暂时不可用)。我现在得到的部署错误是关于这一行的:

ResourceBundle resourceBundle = portletConfig.getResourceBundle(locale);

Duplicate local variable resourceBundle__60: <portlet:defineObjects />__61: __62: <%__63: ResourceBundle resourceBundle = portletConfig.getResourceBundle(locale);

这些是我的 portlet web-inf/tld 文件夹中的 TLD:

aui.tld
c-rt.tld
liferay-portlet-ext.tld
liferay-security.tld
liferay-theme.tld
liferay-ui.tld
liferay-util.tld

我尝试将 liferay-portlet.tld 添加到此文件夹,但它也不起作用,这是我的 web.xml,如您所见,我定义了 portlet.tld

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5" 

xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<display-name>Valisa</display-name>
<context-param>
    <param-name>company_id</param-name>
    <param-value>aoc</param-value>
</context-param>

<listener>
    <listener-class>com.liferay.portal.kernel.servlet.PortletContextListener</listener-class>
</listener>

<listener>
    <listener-class>net.opentrends.caoc.portlet.valisa.portlet.ListenerStartup</listener-class>
</listener>

<servlet>
    <servlet-name>valisa</servlet-name>
    <servlet-class>com.liferay.portal.kernel.servlet.PortletServlet</servlet-class>
    <init-param>
        <param-name>portlet-class</param-name>
        <param-value>net.opentrends.caoc.portlet.valisa.portlet.ValisaPortlet</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
</servlet>
<servlet>
    <servlet-name>dwr-invoker</servlet-name>
    <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
    <init-param>
        <param-name>debug</param-name>
        <param-value>true</param-value>
    </init-param>
</servlet>
    <servlet>
    <servlet-name>DescarregarDocumentAdjuntServlet</servlet-name>
    <servlet-class>cat.aoc.eacatpl.valisa.servlet.DescarregarDocumentAdjuntServlet</servlet-class>
</servlet>
<servlet>
    <servlet-name>ObtenirCorreuElectronicAjaxServlet</servlet-name>
    <servlet-class>cat.aoc.eacatpl.valisa.servlet.ObtenirCorreuElectronicAjaxServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>valisa</servlet-name>
    <url-pattern>/valisa2014-portlet/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>dwr-invoker</servlet-name>
    <url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>DescarregarDocumentAdjuntServlet</servlet-name>
    <url-pattern>/ajax/descarregarDocumentAdjunt</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>ObtenirCorreuElectronicAjaxServlet</servlet-name>
    <url-pattern>/ajax/obtenirCorreuContactes</url-pattern>
</servlet-mapping>


<jsp-config>    
    <taglib>
        <taglib-uri>http://java.sun.com/portlet</taglib-uri>
        <taglib-location>/WEB-INF/tld/liferay-portlet.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>http://liferay.com/tld/theme</taglib-uri>
        <taglib-location>/WEB-INF/tld/liferay-theme.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>http://liferay.com/tld/ui</taglib-uri>
        <taglib-location>/WEB-INF/tld/liferay-ui.tld</taglib-location>
    </taglib>
    <taglib>
        <taglib-uri>http://liferay.com/tld/util</taglib-uri>
        <taglib-location>/WEB-INF/tld/liferay-util.tld</taglib-location>
    </taglib>
</jsp-config>

任何帮助将不胜感激。

【问题讨论】:

  • 请分享 pom.xml,我想它可能缺少依赖项。
  • 你能告诉我那个文件在哪里吗? @astrohome。我在我的 portlet 档案中找不到它。谢谢!
  • 啊,好吧,也许你没有使用 Maven 进行依赖管理。在这种情况下,您使用的是什么系统?常春藤?
  • 我确定我没有使用 Maven 进行依赖项管理,但老实说,我不能真正告诉你我是否使用 Ivy,如果我想添加一个依赖项,我只需将它添加到 java 构建小路。抱歉,我对此真的很陌生。 @astrohome
  • 根据错误,它发现范围内定义了相同的变量。简单的解决方法是重命名变量名。

标签: java eclipse liferay portlet


【解决方案1】:
  1. 顶级域名

Liferay 在部署时自动添加 TLD。只需查看容器中已部署的 portlet 目录,例如在 tomcat 中为${catalina.home}/webapps/your-portlet(它也会对 web.xml 进行一些更改,您可以看看以更好地理解 Liferay)。

当然 Eclipse 不会知道这一点,但如果您将 TLD 放在完全相同的位置,您应该没问题。确保使用正确的 Liferay 版本的 TLD——您可以简单地使用在已部署的 portlet 中找到的那些。

  1. 无法解析的变量

Eclipse 也很难从不同的标签中推断出所有的副作用。很可能一切都很好,因为localeportletConfig 是由defineObjects 标签添加的,我可以看到你的JSP 中确实有。这些警告很烦人,但我真的不知道是否可以对它们做点什么。

  1. 例外情况

正如其中一个 cmets 所述,您可能尝试定义一个已在别处定义的变量。可能在某个标记中,如第 2 点所述。重命名变量或删除分配并使用已定义的变量。

【讨论】:

    【解决方案2】:

    尝试在您的 web.xml 中更改它:

    <taglib>
        <taglib-uri>http://java.sun.com/portlet</taglib-uri>
        <taglib-location>/WEB-INF/tld/liferay-portlet.tld</taglib-location>
    </taglib>
    

    替换成

    <taglib>
        <taglib-uri>http://java.sun.com/portlet_2_0</taglib-uri>
        <taglib-location>/WEB-INF/tld/liferay-portlet.tld</taglib-location>
    </taglib>
    

    因为 portlet_2_0 是这个标签库的实际 namespace。冲洗重复 - 这将开始摆脱第一个错误 - 因为它是关于编译,通常修复根本原因修复更多内容。如果没有,请报告。

    【讨论】:

      猜你喜欢
      • 2012-09-10
      • 2011-07-12
      • 1970-01-01
      • 2022-01-24
      • 2013-05-04
      • 1970-01-01
      • 2017-08-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多