`
makeithappen
  • 浏览: 9805 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
最近访客 更多访客>>
社区版块
存档分类
最新评论

Portlet - Apache Pluto - Hello World Portlet

 
阅读更多

This is document just for documenting the steps for the helloworld sample which i did for learning pluto.

 

It takes two night for me succesfully deployed a helloworld in apache pluto portal server, i learned lots of thing in recently two night in learning using pluto even how the portlet should be configured in order to get it working in apache pluto.

 

so, below the steps for deploying a helloworld in apache pluto.

 

1. we should have successfully installed apache pluto open source portal server in our local.

 

2. create a helloword portleot application and its strcuture like below:

 

\---ch1_HelloWorld
    |   build-pluto.xml
    |   build.properties
    +---lib
    |       junit-4.7.jar
    |       portlet-api_2.0_spec-1.0.jar
    +---src
    |   \---chapter01
    |       \---code
    |           \---listing
    |                   HelloWorldPortlet.java
    \---WEB-INF
        |   portlet.xml
        |   web.xml
        \---jsp
        \---lib
 

 

 

3. let's start for each files mentioned in above structure

 

3.1 file chapter01.code.listing.HelloWorldPortlet

 

package chapter01.code.listing;

import java.io.IOException;
import java.io.PrintWriter;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

public class HelloWorldPortlet extends GenericPortlet {
	protected void doEdit(RenderRequest request, RenderResponse response)throws PortletException, IOException {
		response.setContentType("text/html");
		PrintWriter writer = new PrintWriter(response.getWriter());
		writer.println("You're now in Edit mode.");
	}

	protected void doHelp(RenderRequest request, RenderResponse response)throws PortletException, IOException {
		response.setContentType("text/html");
		PrintWriter writer = new PrintWriter(response.getWriter());
		writer.println("You're now in Help mode.");
	}

	protected void doView(RenderRequest request, RenderResponse response)throws PortletException, IOException {
		response.setContentType("text/html");
		PrintWriter writer = new PrintWriter(response.getWriter());
		writer.println("Hello world! You're in View mode.");
	}
}
 

3.2 file web.xml

 

<?xml version="1.0"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"
	version="2.5">
	<display-name>Hello World portlet application</display-name>
	<servlet>
		<servlet-name>HelloWorldPortlet</servlet-name>
		<servlet-class>
			org.apache.pluto.container.driver.PortletServlet
		</servlet-class>
		<init-param>
			<param-name>portlet-name</param-name>
			<param-value>HelloWorldPortlet</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
		<supports>
			<mime-type>text/html</mime-type>
			<portlet-mode>VIEW</portlet-mode>
			<portlet-mode>EDIT</portlet-mode>
			<portlet-mode>HELP</portlet-mode>
		</supports>
		<portlet-info>
			<title>Hello, This is my first portlet application</title>
		</portlet-info>
	</servlet>
	<servlet-mapping>
		<servlet-name>HelloWorldPortlet</servlet-name>
		<url-pattern>/PlutoInvoker/HelloWorldPortlet</url-pattern>
	</servlet-mapping>
</web-app>

 

 

3.3 file portlet.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"
	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">
	<portlet>
		<portlet-name>HelloWorldPortlet</portlet-name>
		<display-name>Hello World Portlet</display-name>
		<portlet-class>chapter01.code.listing.HelloWorldPortlet</portlet-class>
		<supports>
			<mime-type>text/html</mime-type>
			<portlet-mode>VIEW</portlet-mode>
			<portlet-mode>EDIT</portlet-mode>
			<portlet-mode>HELP</portlet-mode>
		</supports>
		<portlet-info>
			<title>Hello, This is my first portlet application</title>
		</portlet-info>
	</portlet>
</portlet-app>
 

 

3.4 file build.properties

 

pluto.portal.home=G:/Environment/Portal/pluto-2.0.3
 

 

3.5 file build-pluto.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<project name="HelloWorldPortlet" default="rebuild" basedir=".">
	
	<property file="build.properties" />
	<property environment="env"/>
	
	<property name="AppName" value="HelloWorldPortlet"/>
	<property name="debug" value="on"/>
	<property name="dir.build" value="pluto_build"/>
	<property name="dir.src" value="src"/>
	<property name="dir.classes" value="pluto_classes"/>
	<property name="dir.lib" value="pluto_lib"/>
	<property name="dir.war" value="${basedir}/"/>
	<property name="dir.war.lib" value="${dir.war}/WEB-INF/lib"/>
	<property name="dir.driver" value="pluto_driver"/>
	<property name="portlet.api" value="portlet-api_2.0_spec-1.0.jar"/>
	<property name="pluto.home" value="${pluto.portal.home}"/>
	
	<target name="build" depends="build.war"/>
	
	<target name="rebuild" depends="clean,build"/>
	
	<target name="init">
		<mkdir dir="${dir.build}"/>
		<mkdir dir="${dir.classes}"/>
		<mkdir dir="${dir.lib}"/>
		<mkdir dir="${dir.driver}"/>
		<mkdir dir="${dir.war.lib}"/>
		<copy file="${pluto.home}/api/target/${portlet.api}" todir="${dir.lib}" failonerror="no"/>
	</target>
	
	<target name="env" depends="init">
		<echo message="Portlet Application: ${AppName} "/>
	</target>
	
	<target name="compile" depends="env">
		<javac srcdir="${dir.src}" destdir="${dir.classes}" includes="**/*.java" debug="${debug}">
			<classpath>
				<fileset dir="${dir.war.lib}">
					<include name="**/*.jar"/>
				</fileset>
				<fileset dir="${dir.lib}">
					<include name="**/*.jar"/>
				</fileset>
			</classpath>
		</javac>
	</target>
	
	<target name="build.jar" depends="compile">
		<jar jarfile="${dir.classes}/${AppName}.jar" compress="true">
			<fileset dir="${dir.classes}">
				<exclude name="*.jar"/>
			</fileset>
		</jar>
	</target>
	
	<target name="build.war" depends="build.jar">
		<jar jarfile="${dir.driver}/${AppName}.war">
			<fileset dir="${dir.war}/">
				<include name="**/WEB-INF/**"/>
			</fileset>
			<zipfileset dir="${dir.classes}" prefix="WEB-INF/lib">
				<include name="*.jar"/>
			</zipfileset>
		</jar>
	</target>
	
	<target name="clean">
		<delete dir="${dir.classes}" failonerror="false" />
		<delete dir="${dir.driver}" failonerror="false"/>
	</target>
	
</project>

 

 

4. after we have those code in the portlet project, we can successfully generate one portlet war application file HelloWorldPortlet.war.

 

5. we have to copy the HelloWorldPortlet.war file into <pluto_home>\PlutoDomain directory.

 

6. next, we have to create a file 'hello.xml' for deploy this portlet application under <pluto_home>\conf\Catalina\localhost

 

 

hello.xml

 

 

<Context path="hello" docBase="../PlutoDomain/HelloWorldPortlet.war" crossContext="true"></Context>
 

 

7. then, we have to configure the HelloWorldPortlet in pluto-portal-driver-config.xml in order to get it shown on the pluto portlet page; 

 

     file <pluto-portal-driver-config.xml> path: <pluto_home>\webapps\pluto\WEB-INF\pluto-portal-driver-config.xm

 

<?xml version="1.0" encoding="UTF-8"?>
<pluto-portal-driver
    xmlns="http://portals.apache.org/pluto/xsd/pluto-portal-driver-config.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://portals.apache.org/pluto/xsd/pluto-portal-driver-config.xsd
                        http://portals.apache.org/pluto/pluto-portal/2.0/pluto-portal-driver-config.xsd"
    version="1.1">
  <portal-name>pluto-portal-driver</portal-name>
  <portal-version>2.0.3</portal-version>
  <container-name>Pluto Portal Driver</container-name>
  <supports>
    <portlet-mode>view</portlet-mode>
    <portlet-mode>edit</portlet-mode>
    <portlet-mode>help</portlet-mode>
    <portlet-mode>config</portlet-mode>
    <window-state>normal</window-state>
    <window-state>maximized</window-state>
    <window-state>minimized</window-state>
  </supports>

   <render-config default="About Apache Pluto">
    <page name="About Apache Pluto" uri="/WEB-INF/themes/pluto-default-theme.jsp">
      <portlet context="/pluto" name="AboutPortlet"/>
      <portlet context="/testsuite" name="TestPortlet1"/>
      <portlet context="/hello" name="HelloWorldPortlet"/>
    </page>
    <page name="Test Page" uri="/WEB-INF/themes/pluto-default-theme.jsp">
      <portlet context="/testsuite" name="TestPortlet1"/>
      <portlet context="/testsuite" name="TestPortlet2"/>
      <portlet context="/hello" name="HelloWorldPortlet"/>
    </page>
    <page name="JSR 286 Tests" uri="/WEB-INF/themes/pluto-default-theme.jsp">
      <portlet context="/testsuite" name="286TestPortlet"/>
      <portlet context="/testsuite" name="286TestCompanionPortlet"/>
      <portlet context="/hello" name="HelloWorldPortlet"/>
    </page>
    <page name="Pluto Admin" uri="/WEB-INF/themes/pluto-default-theme.jsp">
      <portlet context="/pluto" name="PlutoPageAdmin"/>
      <portlet context="/pluto" name="AboutPortlet"/>
      <portlet context="/pluto" name="PlutoPageAdmin"/>
      <portlet context="/hello" name="HelloWorldPortlet"/>
    </page>
    <page name="Sample Portals" uri="/WEB-INF/themes/pluto-default-theme.jsp">
      <portlet context="/hello" name="HelloWorldPortlet"/>
    </page>
  </render-config>
</pluto-portal-driver>
 

 

8. after we done all above steps, then, start the pluto portal server, the helloworld portlet application will looks like below:

 

 

 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

    Portlet HelloWorld Pluto2+myeclips6+tomcat6詳細開發指南

    【Portlet HelloWorld Pluto2+myeclips6+tomcat6详细开发指南】 在Web开发领域,Portlet是一种可重用的、独立的组件,它能够嵌入到portlet容器(如Pluto)中,与其他portlet共享一个页面。本指南将详细介绍如何使用...

    portlet hello world程序

    开发portlet可以使用Eclipse IDE搭配portlet插件,或者使用Maven或Gradle这样的构建工具配合portlet-maven-plugin或gradle-portlet-plugin。这些工具可以帮助开发者自动化构建、测试和部署portlet。 7. **portlet...

    struts-portlet 开发

    此命令创建了一个名为`bookmark-portlet`的样例项目,其中包含了基本的HelloWorld Portlet。 #### 五、测试Struts-Portlet项目 1. **启动Jetty服务器**:在命令行中输入以下命令启动Jetty服务器: ```bash mvn ...

    struts2-portlet学习手册

    &lt;description xml:lang="EN"&gt;Simple helloworld portlet ... ``` 此段代码定义了一个名为`HelloPortlet`的Portlet,其中包含了对Portlet的一些基本信息的描述。 #### 六、核心概念 - **MVC架构**:Struts2-...

    Portlets and Apache Portals

    - **portlet示例:Hello World**:通过一个简单的“Hello World”示例,展示portlet的基本功能和开发流程。 #### 四、门户与portlet概览 - **什么是门户?**:门户是一个集成平台,能够提供个性化的内容和服务。...

    Manning Portlets and Apache Portals

    - **实例代码**:通过一个简单的示例来展示如何编写Portlet代码,例如实现一个显示“Hello World”的Portlet。 #### 1.5 创建Portlet部署描述符 - **部署描述符**:解释了什么是部署描述符,以及它在部署Portlet中...

    Portlet 入门实例

    以"HelloWorld"为例,这是一个典型的Portlet入门程序,它将展示如何创建一个简单的Portlet。这个例子可能会包含以下步骤: 1. **创建portlet项目**:使用Maven或Eclipse IDE创建一个新的portlet项目,设置必要的...

    Portlets的知识

    **开发“Hello World”Portlet** 创建一个基本的Portlet涉及到实现Portlet接口,定义初始化、销毁方法,以及处理不同类型的动作和渲染请求的方法。开发者需要编写处理用户交互的代码,并生成HTML响应片段,这些片段...

    struts2经典实例

    `struts2-portlet-2.0.1.war` 展示了Struts2与portlet容器的集成,如Liferay或Pluto。这在企业级应用中尤其重要,因为portlet可以部署在门户服务器上,与其他应用进行交互。这个实例有助于理解portlet开发和Struts2...

Global site tag (gtag.js) - Google Analytics