`
Clayz
  • 浏览: 297630 次
  • 性别: Icon_minigender_1
  • 来自: 东京
社区版块
存档分类
最新评论

Liferay plugin开发入门

阅读更多

本篇部分引用以下文章:

http://daoger.iteye.com/blog/359826

 

首先下载liferay-tomcat-bundle和liferay-plugin-SDK,将其解压直系统任意目录。

进入liferay-plugin-SDK目录,新建plugin项目:

ant -Dportlet.name=<project name> -Dportlet.display.name="<portlet title>" create
 

新建Eclipse Java项目LiferayPlugin,将liferay-plugin-SDK解压后的目录拷贝至里面。将Liferay需要的jar加入环境变量(主要包括tomcat/webapps/ROOT/WEB-INF/lib和tomcat/common/lib/ext两个文件夹里面的jar)

 

在LiferayPlugin目根目录下,新建资源文件build.{username}.properties,这里的username是你的计算机用户名称。然后在build.{username}.properties文件中添加app.server.dir这一个属性,它的值指向tomcat的目录。

 

build新建的portlet项目,此后运行Liferay,就可在plugin中看见发布的portlet。

 

以下引用ipc-baseball-portlet.rar 中的部分源码:

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
    <listener>
        <listener-class>com.liferay.portal.kernel.spring.context.PortletContextLoaderListener</listener-class>
    </listener>
    <taglib>
        <taglib-uri>http://java.sun.com/jstl/core_rt</taglib-uri>
        <taglib-location>/WEB-INF/tld/c-rt.tld</taglib-location>
    </taglib>
</web-app>

 

<?xml version="1.0"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
	<!-- <default-namespace>http://liferay.com/events</default-namespace> -->
	<portlet>
		<portlet-name>pitcher-portlet</portlet-name>
		<display-name>Pitcher Portlet</display-name>
		<portlet-class>com.liferay.ipc.PitcherPortlet</portlet-class>
		<init-param>
			<name>view-jsp</name>
			<value>/pitcher/view.jsp</value>
		</init-param>
		<expiration-cache>0</expiration-cache>
		<supports>
			<mime-type>text/html</mime-type>
		</supports>
		<portlet-info>
			<title>Pitcher Portlet</title>
			<short-title>Pitcher Portlet</short-title>
			<keywords>IPC Baseball Pitcher</keywords>
		</portlet-info>
		
		<security-role-ref>
			<role-name>administrator</role-name>
		</security-role-ref>
		<security-role-ref>
			<role-name>guest</role-name>
		</security-role-ref>
		<security-role-ref>
			<role-name>power-user</role-name>
		</security-role-ref>
		<security-role-ref>
			<role-name>user</role-name>
		</security-role-ref>
		
		<supported-publishing-event>
			<qname xmlns:x="http://liferay.com/events">x:ipc.pitch</qname>
		</supported-publishing-event>
	</portlet>
	
	<event-definition>
		<qname xmlns:x="http://liferay.com/events">x:ipc.pitch</qname>
		<value-type>java.lang.String</value-type>
	</event-definition>
</portlet-app>

 

/**
 * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.liferay.ipc;

import java.io.IOException;
import java.util.Random;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.ProcessAction;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.xml.namespace.QName;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * This portlet demonstrates the new Event model in JSR-286
 * that is used to achieve Inter-Portlet Communication. This portlet 
 * will "throw" an event out there for another portlet to catch. 
 *
 * @author Rich Sezov
 *
 */
public class PitcherPortlet extends GenericPortlet {
    public void init() throws PortletException {
        editJSP = getInitParameter("edit-jsp");
        helpJSP = getInitParameter("help-jsp");
        viewJSP = getInitParameter("view-jsp");
    }

    public void doDispatch(RenderRequest req, RenderResponse res) throws IOException, PortletException {
        String jspPage = req.getParameter("jspPage");

        if (jspPage != null) {
            include(jspPage, req, res);
        } else {
            super.doDispatch(req, res);
        }
    }

    public void doEdit(RenderRequest req, RenderResponse res) throws IOException, PortletException {
        if (req.getPreferences() == null) {
            super.doEdit(req, res);
        } else {
            include(editJSP, req, res);
        }
    }

    public void doHelp(RenderRequest req, RenderResponse res) throws IOException, PortletException {
        include(helpJSP, req, res);
    }

    public void doView(RenderRequest req, RenderResponse res) throws IOException, PortletException {
        include(viewJSP, req, res);
    }

    protected void include(String path, RenderRequest req, RenderResponse res) throws IOException, PortletException {
        PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher(path);

        if (prd == null) {
            _log.error(path + " is not a valid include");
        } else {
            prd.include(req, res);
        }
    }

    /**
     * Since Portlet 2.0's GenericPortlet class lets you call methods 
     * from processAction via annotations, we don't even need to touch the 
     * processAction method to call our actions. 
     * 
     */
    @ProcessAction(name = "pitchBall")
    public void pitchBall(ActionRequest request, ActionResponse response) {
        String pitchType = null;
        // Send an Event that the ball has been pitched.
        Random random = new Random(System.currentTimeMillis());
        int pitch = random.nextInt(3) + 1;
        switch (pitch) {
            case 1:
                pitchType = "Fast Ball";
                break;
            case 2:
                pitchType = "Curve Ball";
                break;
            case 3:
                pitchType = "Slider";
                break;
            // should never print
            default:
                pitchType = "Screw Ball";
        }
        QName qName = new QName("http://liferay.com/events", "ipc.pitch");
        response.setEvent(qName, pitchType);
    }

    protected String editJSP;
    protected String helpJSP;
    protected String viewJSP;

    private static Log _log = LogFactory.getLog(PitcherPortlet.class);
}
 
<%
/**
 * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
%>

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

<portlet:defineObjects />
<p>Click the link below to pitch the ball. </p>
<a href="<portlet:actionURL name="pitchBall"></portlet:actionURL>">Pitch!</a>
 
分享到:
评论

相关推荐

    liferay的开发文档

    Liferay Plugin SDK是开发Liferay插件的工具包。这份文档详述了如何使用SDK创建和管理各种插件,如钩子、布局、工作流定义等。开发者将学习到如何使用Ant脚本部署插件,以及如何利用Liferay的API扩展其功能。此外,...

    Liferay入门帮助文档(Liferay开发指南)

    Liferay入门帮助文档是针对Liferay开发的一份指南,它主要涵盖了如何开始使用这个全面的门户解决方案。Liferay是一个基于Java Enterprise Edition (J2EE) 的应用,它整合了多种技术,如EJB (Enterprise JavaBeans) ...

    LIferay6开发书籍

    开发者将学习到如何利用Liferay的服务架构来开发可扩展、高性能的应用,并且理解Liferay的模块化设计,如ServiceBuilder、Hook、Ext Plugin等。 其次,《Liferay 用户开发接口》深入解析了Liferay中的用户管理和...

    liferay6.2开发指南.pdf

    【Liferay 6.2 开发指南】 Liferay 6.2 是一个开源的企业级门户平台,它提供了丰富的功能和高度可扩展性,适合构建企业内部或外部的协作、信息共享和业务应用集成的网站。本开发指南将帮助开发者深入理解 Liferay ...

    liferay快速入门quickstart

    ### Liferay快速入门知识点详解 #### 一、Liferay Portal简介与快速启动 ...无论是对于希望快速搭建企业门户的用户,还是想要深入探索Liferay开发的开发者,这份快速入门指南都是一个不可或缺的资源。

    Liferay 主题开发官方文档中文翻译

    ### Liferay 6.2 主题开发中文指南 #### 一、引言 在现代Web开发领域中,网站不仅需要具备强大的功能,还需要拥有吸引人的视觉设计与良好的用户体验。Liferay作为一款开源的企业级门户平台,提供了丰富的工具与...

    liferay 6.2开发指南+用户手册

    Liferay 6.2是一款流行的开源企业级门户平台,它提供了丰富的功能,包括内容管理、社交媒体集成、工作流程以及自定义开发能力。本指南将基于提供的"liferay 6.2开发指南+用户手册"来深入讲解其核心知识点。 1. **...

    liferay portal 开发实例

    6. **部署描述符**:如liferay-plugin-package.xml,定义portlet的部署信息,如版本、依赖、资源引用等。 7. **资源权限**:Liferay支持细粒度的资源权限控制,开发者可以为portlet定义不同级别的访问权限。 8. **...

    liferay 6.0 开发指南

    ### Liferay 6.0 开发指南核心知识点详解 #### 一、引言与核心技术 在《Liferay 6.0 开发指南》中,首先介绍了Liferay 6.0的核心技术及其开发策略。Liferay是一款强大的开源门户平台,支持企业级应用的构建与部署...

    Liferay 6 入门教程

    此外,"plugins开发指南11-plugin中开发hibernate应用.pdf"涵盖了在Liferay中使用Hibernate进行数据持久化的实践方法,这对于处理复杂业务逻辑至关重要。 "plugins开发指南13-liferay中使用ldap分析.pdf"讨论了...

    liferay portal开发大全

    **Liferay Portal 开发大全** Liferay Portal 是一个开源的企业级门户平台,广泛用于构建复杂的Web应用程序和企业内部协作系统。它提供了丰富的功能,包括内容管理、社交媒体集成、工作流支持以及用户界面定制。本...

    liferay portlet开发

    本文档旨在详细介绍如何通过插件(plugin)方式开发Liferay Portlet。 #### 二、开发模式的选择 Liferay提供了两种主要的扩展开发方式: 1. **Ext 方式**:这种方式的优点是可以利用Liferay现有的所有模板内容,...

    7z压缩,三合一-LifeRay-开发参考手册&二次开发指南&4.3中文开发指南

    【标题】"7z压缩,三合一-LifeRay-开发参考手册&二次开发指南&4.3中文开发指南" 涵盖了LifeRay平台的重要学习资源,这些文档为开发者提供了全面的指导,帮助他们理解并掌握LifeRay的开发技术。 【描述】中提到的三...

    liferay开发文档集合

    《Liferay开发文档集合》是针对企业级门户平台Liferay的一系列技术指南,涵盖了从基础安装到高级定制的全方位知识。这些PDF文档旨在帮助开发者、系统管理员和IT专业人员更好地理解和利用Liferay Portal来构建和管理...

    Liferay开发文档整理.pdf

    通过上述内容的整理和总结,可以看出文档主要介绍了Liferay开发的基础概念,包括Liferay的版本信息、Portlet开发、主题和布局模板的自定义、插件SDK和Liferay IDE的使用,以及如何配置开发环境。同时,也涉及了...

    Liferay 6.2 开发环境搭建

    Liferay 6.2 开发环境搭建.doc,包括Liferay SDK下载及搭建过程等!

    LifeRay框架开发手册,PORTAL类一个开发框架Liferay

    LifeRay架构开发手册,liferay Portal开发解析等精彩文章

    liferay6.2开发完全指南

    《Liferay 6.2 开发完全指南》是一本针对Liferay最新版本6.2的详尽教程,旨在帮助开发者全面理解和掌握Liferay平台的开发技术。本教程以Liferay官方的技术文档为基础,同时提供了配套的视频教程,使得学习过程更为...

    liferay6.2开发指南

    liferay6.2开发指南liferay6.2开发指南.doc

Global site tag (gtag.js) - Google Analytics